Python 3.11.0 | packaged by conda-forge | (main, Jan 16 2023, 14:12:30) [MSC v.1916 64 bit (AMD64)]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.10.0 -- An enhanced Interactive Python. Type '?' for help.

In [ ]:
import os
import sys
from functools import partial
sys.path.append(os.path.join(os.getcwd(), '..')) #adds directory below as valid path
from  datetime import datetime, timedelta
dateformat = "%H-%M-%S"
from collections import deque
import traceback
from multiprocessing import Pool
from tqdm import tqdm

import scipy.constants as spc
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd

plt.rcParams['axes.grid'] = True
plt.rcParams['grid.linestyle'] = '--'

from MT_class_PID_new import MTdataHost
from global_folder.myplotsty import *
from global_folder.my_helpers import *

PUMP_FREQUENCY = 384228.6
REPUMP_FREQUENCY = 384228.6 + 6.56
SAMPLE_RATE = 2000
FREQVSVOLT = 221.0 
FREQVSCURR = 1.13

# TODO: find a better place for this
EXP_FOLDER =r'C:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\CATMeasurements'
MEASURE_FOLDER = os.path.join(EXP_FOLDER, 'testPArun16')
WDATA_FOLDER =os.path.join(MEASURE_FOLDER, 'testPArun16.csv')

# TODO: maybe make a run analysis class out of this?
def dump():
	fig, ax = plt.subplots()
	plot_results(ax, df, max_freq= 384219., fmt='o', mfc='red', save_folder=MEASURE_FOLDER)
	plt.savefig(os.path.join(MEASURE_FOLDER, 'ratio_vs_freq.png'))

	
	collect_plots(MEASURE_FOLDER, os.path.join(MEASURE_FOLDER, 'collected_plots'), 'deloadPhase.png')
 
	#*-----------------------
	#* SINGLE RUN
 	#*----------------------- 
  
	MEASURE_FOLDER = os.path.join(EXP_FOLDER, 'testPArun9')
	df = get_data_frame(MEASURE_FOLDER)
	df.dropna(inplace=True)
	#freqs = plot_results(df, 384201., save_folder=MEASURE_FOLDER)
 
	data = df.dropna()
	freqs = ((384201-PUMP_FREQUENCY)-(data['tempV']-df['tempV'].min())*FREQVSVOLT- (data['currV']-df['currV'].min())*FREQVSCURR)
	fig, ax = plt.subplots()
	plot_spline_fit(ax=ax, x=freqs, y=data['ratio'], yerr=data['ratioErr'], 
				 s=0.1, save_folder=MEASURE_FOLDER, 
				 mfc='red', color='black', 
				 title='Trap Depth = 1.99 K')
 
	# *-----------------------
	# * MULTIPLE RUN COMPARISON
 	# *-----------------------
	folders = [os.path.join(EXP_FOLDER, path ) for path in ['testPARun11', 'testPARun12', 'testPARun13', 'testPARun14']]
	dfs = [get_data_frame(measure_folder, cache_all=True) for measure_folder in folders]

	colors = ['red', 'dodgerblue', 'green', 'grey']
	max_freqs = [384178.881, 384178.593,384179.068, 384184.731]
	#max_freqs=[384178.599, 384179.091, 384184.733]

	zipped_data = list(zip(dfs, max_freqs))
	fig, ax = plt.subplots()
	for i, (df, max_freq)  in enumerate(zipped_data[:3]):
		data = df.dropna()
		freqs = ((max_freq-PUMP_FREQUENCY)-(data['tempV']-data['tempV'].min())*FREQVSVOLT- (data['currV']-data['currV'].min())*FREQVSCURR)
		color = colors[i]
		ax=plot_spline_fit(ax, x=freqs, y=data['ratio'], scolor=color, mfc=color,color=color, s=0.02, ms=5)

	#*-----------------------
	#* PARSING WAVEMETER DATA
 	#*-----------------------

	MEASURE_FOLDER = os.path.join(EXP_FOLDER, 'testPArun14')
	WDATA_FOLDER =os.path.join(MEASURE_FOLDER, 'testPArun14.csv')
	freq_data, max_freq, min_freq = add_wavemeter_data('', WDATA_FOLDER)
	data = freq_data[:]
	levels = staircase_fit(data)

	data = get_data_frame(MEASURE_FOLDER)
	data.dropna(inplace=True)
	freqs = ((max_freq)-(data['tempV']-data['tempV'].min())*FREQVSVOLT- (data['currV']-data['currV'].min())*FREQVSCURR)
	plt.plot(freqs)
 
	#*-----------------------
	#* GETTING DEPTH_RATIO DATAFRAME
 	#*-----------------------
	MEASURE_FOLDER = r'C:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\CATMeasurements\relScatRate'
	depth_ratios_df = get_rel_scattering_df(MEASURE_FOLDER)
	df_slice = depth_ratios_df[(depth_ratios_df['pa1']==1.85) & (depth_ratios_df['pd1']==84) & (depth_ratios_df['pd2'] == 84)]
	x = df_slice['pa2']
	y = df_slice['depth_ratio']
	plt.plot(x,y, 'o')

	#*-----------------------
	#* MEGA_RUN
 	#*-----------------------	
	MEASURE_FOLDER = os.path.join(EXP_FOLDER, 'testPARunMega')
	df = get_data_frame(MEASURE_FOLDER)
	df.dropna(inplace=True)

	df_grouped = df.groupby(by='pump_reference')
	min_ratios = df_grouped['ratio'].min()

	groups = dict(list(df_grouped))
	dfs = [df for df in groups.values()]
 
	max_freqs = [384182.5]*15
	#max_freqs=[384178.599, 384179.091, 384184.733]
	zipped_data = list(zip(dfs, max_freqs))
	fig, ax = plt.subplots()
	for i, (df, max_freq)  in enumerate(zipped_data[:]):
		data = df.dropna()
		freqs = ((max_freq-PUMP_FREQUENCY)-(data['tempV']-data['tempV'].min())*FREQVSVOLT- (data['currV']-data['currV'].min())*FREQVSCURR)
		ax=plot_spline_fit(ax, x=freqs, y=data['ratio'], yerr=data['ratioErr'],scolor=f'C{i}', mfc=f'C{i}',color=f'C{i}', s=0.0, ms=5, figsize=(10, 10), label=f"Pump Amplituide = { df.iloc[10]['pump_reference'] :.2f}", linewidth=2.5)

	plt.legend()

	plt.savefig(os.path.join(MEASURE_FOLDER, 'lossFeatures.png'))
	#*-----------------------
	#* MULTIPLE MEGARUN
	#*-----------------------
 
	folders = [os.path.join(EXP_FOLDER, path ) for path in ['testPArunMega', 'testPArunMega2']]
	dfs_mega = [get_data_frame(measure_folder, cache_all=True).dropna() for measure_folder in folders]

	dfs_grouped = [df_mega.groupby(by='pump_reference') for df_mega in dfs_mega]
	min_ratios = [df_grouped['ratio'].min() for df_grouped in dfs_grouped]

	groupss = [dict(list(df_grouped)) for df_grouped in dfs_grouped]
	dfs = [ [df for df in groups.values()] for groups in groupss]
 
	for row in dfs:
		x = [df['pump_reference'].mean() for df in row]
		y = [(df['ratio'].max() - df['ratio'].min())/df['motSS'].std() for df in row]
		plt.plot( x, y ,'-o', label=fr"$\delta$ = {180 - 2*row[0]['pump_AOM_freq'].mean()} MHz")
		plt.xlabel('Pump Amplitude')
		plt.ylabel(r'SNR $ = \frac{V_{ss, off} - V_{ss, on}}{\sigma_{V,off}}$ ')
	plt.legend()

def freq_misc():
	WDATA_FOLDER = r'C:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\CATMeasurements\CATcurrTestrun3.csv'
	freq_data = add_wavemeter_data('', WDATA_FOLDER)
	levels = staircase_fit(freq_data[0], peak_height=0.2, distance=50, data_offset=1, window_size=1) 

	plt.close()
 
	x = np.linspace(0, 4.9, 25)
	y = levels
 
	plt.plot(levels, '-o')
	plt.title('Levels plot')
	
	m, b, fit_line = my_linear_fit(x, y)
def save_fit_results(run_path, plot=False):
	filename = os.path.join(run_path, 'data.csv')
	bkfilename = os.path.join(run_path, 'data_oldPD.csv')
	settingsname = os.path.join(run_path, 'Settings.txt')
	
	dataHost = MTdataHost(SAMPLE_RATE)
	dataHost.loadCATdata(fileName=filename, settingsName=settingsname)
	dataHost.CATbackgroundData(bkfilename)
	
	dataHost.setAllCAT(0.002)
	resultDict = dataHost.getResults(run_path, store=True)
 
	if plot:
		dataHost.storeFits(run_path, combined=True, separate=True)
  
	return resultDict, dataHost.settings
		
def get_timestamp(run_path):
	timestamp = datetime.strptime(os.path.split(run_path)[-1].split('_')[0], dateformat)
	return timestamp

def extract_fit(run_path, plot=True, cache_failed=True, cache_all=True):
	"""Gather relevant data from each measurement run

	Args:
		run_path : absolute path to the run directory
		plot (bool, optional): plot fits. Defaults to True.
		cache_failed (bool, optional): Cache failed fits. If false, refit. Doesn't refit non-failed fits. Defaults to True.
		cache_all (bool, optional): If false, ignore any cached fit_results. Defaults to True.

	Returns:
		a 3-tuple (fit_results, settings, timestamp)
	"""
	fit_results, settings, timestamp = {}, {}, None
	
	if not os.path.isdir(run_path):
		return fit_results, settings, timestamp  # directory is not a run directory

	try:
		timestamp = get_timestamp(run_path)
  
  	# TODO: specify which error to catch
	except Exception as e:
		print("Error extracting timestamp from: ", run_path)
		print(traceback.format_exc())
	
	MAT_fit_cache_path = os.path.join(run_path, 'resultDict.txt')
 
	if not os.path.exists(MAT_fit_cache_path) or not cache_all:
		
		try: 
			fit_results, settings = save_fit_results(run_path, plot=plot)
		except Exception as e:
			print(traceback.format_exc())
			print("Fitting ERROR at ", os.path.basename(run_path), '\n')

			with open(MAT_fit_cache_path, 'w') as f:
				f.write(str('MAT fit failed'))
		
	else:
		print("Accessing cached results from :", os.path.basename(run_path))
  
		fit_results = open(MAT_fit_cache_path, 'r').read()

		if fit_results == 'MAT fit failed':
			if not cache_failed:
				# fit regardless of cached result
				try: 
					fit_results, settings = save_fit_results(run_path, plot=plot)
				except Exception as e:
					print(traceback.format_exc())
					print("Fitting ERROR at ", os.path.basename(run_path), '\n')
	
					with open(MAT_fit_cache_path, 'w') as f:
						f.write(str('MAT fit failed'))	
			else:
				print("Failed fit at :", os.path.basename(run_path))
				fit_results = {}

		else:
			fit_results = eval(open(MAT_fit_cache_path, 'r').read())
   
			settingsname = os.path.join(run_path, 'Settings.txt')
			settings = eval(open(settingsname, 'r').read())
   
	return fit_results, settings, timestamp



def get_row(run_path, **kwargs):
			
   fit_results, settings, timestamp = extract_fit(run_path, **kwargs)
   row = {**fit_results, **settings, **{'timestamp':timestamp}}
   
   return row

   
def get_data_frame(data_dir, parallel=True, in_process_run=False, **kwargs):
   
	run_path_arr = []
	rows = []
	
	for relative_path in os.listdir(data_dir):
		run_path_arr.append(os.path.join(data_dir, relative_path))
  
	if in_process_run:
		run_path_arr.pop()

	run_path_arr = sorted(run_path_arr)
	
	if parallel:
		with Pool(4) as p:
			rows = list(tqdm(p.imap(partial(get_row, **kwargs), run_path_arr), total=len(run_path_arr)))
	
	else:
		for run_path in tqdm(run_path_arr):
		   rows.append(get_row(run_path, **kwargs))

	return pd.DataFrame.from_dict(rows)

def add_wavemeter_data(df, wmeter_csv_path, window_size=100, num_rows=50):


	"""Extract unique frequnecy values from wavemeter data
	Returns:
		unique_levels (list): unique frequency values in wavemeter data
	"""
 
	# TODO: modify dataframe in place with frequency data
 
	wdata = pd.read_csv(wmeter_csv_path, skiprows=2)
	wdata.dropna(inplace=True)
	freq_data = np.array(wdata.iloc[:, 0])
	try:
		freq_data = np.array([float(item) for item in freq_data if item.replace('.','').isdigit()])
	except Exception as e:
		print(e)
 
	max_freq = freq_data.max()
	min_freq = freq_data.min()

	return freq_data, max_freq, min_freq

def plot_results(ax, dfs, max_freq, min_freq=0.0, mfc='red', fmt='o', ms=5, save_folder=False, xscale=1.0, yscale=1.0, **kwargs):
	FREQVSVOLT = 221.0 
	FREQVSCURR = 1.13
	
	if not type(dfs) == list:
		freqs = ((max_freq-PUMP_FREQUENCY)-(dfs.dropna()['tempV']-dfs.dropna()['tempV'].min())*FREQVSVOLT- (dfs.dropna()['currV']-dfs.dropna()['currV'].min())*FREQVSCURR)*xscale
		dfs=[dfs]
  
	plt.gcf().set_dpi(300)
	
	for df in dfs:
		df = df.dropna()
		ax.errorbar(freqs, 
			   df['ratio']*yscale,
			   yerr=df['ratioErr'],
			   fmt=fmt, mfc=mfc, color='black', ms=ms, **kwargs)
		ax.set_ylabel(r'$\mathbf{\frac{V_{ss, cat}}{V_{ss}}} $ ', **labeldict)
		ax.set_xlabel(r'$\Delta $ (GHz)', **labeldict)
	
	if save_folder:
		plt.savefig(os.path.join(save_folder, 'ratio_vs_freq.png'))
	
	return freqs, ax
  
	#return plt.gca(), plt.gcf()
	#plt.show()

def plot_spline_fit(ax, x, y, s=1, yerr=None, color='black', scolor='black',figsize=(12,5), save_folder=None, title='',alpha=0.5,dpi=200, label='plot',**kwargs):
	from scipy.interpolate import splev, splrep
	xnew = np.linspace(min(x), max(x), 3*len(x) )

	y = [b for a,b in sorted(zip(x,y), key=lambda pair: pair[0])]
	if yerr is not None:
		yerr = [b for a,b in sorted(zip(x,yerr), key=lambda pair: pair[0])]
 
	x = sorted(x)

	spl = splrep(x, y, s=s)
	ynew = splev(xnew, spl)

	
	plt.gcf().set_dpi(dpi)
	plt.gcf().set_size_inches(figsize)
	
	if yerr is not None:
		ax.errorbar(x, y, yerr=yerr, fmt='o', **kwargs)
	else:
		ax.plot(x,y, 'o', **kwargs)
	ax.plot(xnew, ynew, '-', color=scolor, alpha=alpha, label=label, **kwargs)
 
	ax.set_ylabel(r'$\mathbf{\frac{V_{ss, cat}}{V_{ss}}} $ ', **labeldict)
	ax.set_xlabel(r'$\Delta $ (GHz)', **labeldict)
 
	ax.set_title(title, **titledict)
	if save_folder:
		plt.savefig(os.path.join(save_folder, 'spline_ratio_vs_freq.png'))
	
	return ax
 
def plot_polyfit(x_data, y_data, spline_degree):
	
	coefficients = np.polyfit(x_data, y_data, spline_degree)

	x_interp = np.linspace(min(x_data), max(x_data), 100)
	y_interp = np.polyval(coefficients, x_interp)

	plt.scatter(x_data, y_data, label='Original Data')
	plt.plot(x_interp, y_interp, label='Polynomial Interpolation (Degree={})'.format(spline_degree))

def collect_plots(source, destination, plot_name):
	print(f'Collecting plots from {os.path.basename(source)}')
	import shutil

	os.makedirs(destination, exist_ok=True)

	plot_files = []
	for root, dirs, files in os.walk(source):
		
		for file in files:
			if file == plot_name:
				plot_files.append(os.path.join(root, file))

	for i, plot_file in enumerate(plot_files, start=0):
		new_filename = f'{i}{plot_name}'
		destination_path = os.path.join(destination, new_filename)
		shutil.copy(plot_file, destination_path)

def create_GIF(images_folder, image_name):
	import imageio
	with imageio.get_writer(os.path.join(images_folder, f'{image_name}movie.gif'), mode='I', duration=0.5) as writer:
		for filename in os.listdir(images_folder):
			if image_name in filename:
				image = imageio.imread(os.path.join(images_folder, filename))
				writer.append_data(image)

def staircase_fit(data, peak_height=0.1, distance=100, data_offset=1, window_size=1, inc_final_peak=True):
	def moving_average(arr, window_size):
		weights = np.ones(window_size) / window_size
		return np.convolve(arr, weights, mode='valid')

	convdata1 = moving_average(data, window_size)
	convdata2 = moving_average(data[data_offset+1:], window_size )
	final = convdata1[:len(convdata2)]-convdata2
	# plt.plot(data)
	# plt.plot(convdata1)
	# plt.plot(convdata2)
	# plt.show()
	# plt.plot(final)

	
	from scipy.signal import find_peaks
	x= final
	peaks, _ = find_peaks(x, height=peak_height, distance=distance)
	peaks = np.insert(peaks, 0, 0)
	levels = []
	plot_arr = []
	for i, peak in enumerate(peaks):
		
		if i < len(peaks) - 1:
			temp = data[ peaks[i]:peaks[i+1] ]
			plot_arr.extend( np.ones_like(temp)*np.mean(temp))
			levels.append(np.mean(temp))
	if inc_final_peak:
		temp = data[peaks[-1]:]
		levels.append(np.mean(temp))
		plot_arr.extend( np.ones_like(temp)*np.mean(temp))
  
	plt.plot(x)
	plt.plot(peaks, x[peaks], "x")
	plt.plot(np.zeros_like(x), "--", color="gray")
	plt.show()
	
	plt.plot(data)
	plt.plot(np.ravel((plot_arr)))
	plt.show()
	plt.close()
	plt.plot(np.array(levels)[np.where(abs(np.diff(levels))>0.05)[0]], 'o', ms=5)
 
	return levels

def load_single_run(run_path):
	filename = os.path.join(run_path, 'data.csv')
	bkfilename = os.path.join(run_path, 'data_oldPD.csv')
	settingsname = os.path.join(run_path, 'Settings.txt')
	
	dh1 = MTdataHost(SAMPLE_RATE)
	dh1.loadCATdata(fileName=filename, settingsName=settingsname)
	
	return dh1
	# *-----------------------
	# *RELATIVE SCATTERING RATE
	# *-----------------------


def get_rel_scattering_df(data_folder):
	depth_ratios_df = []
	listdir = sorted(os.listdir(data_folder))
	try:
		for run_folder1, run_folder2 in [listdir[i:i+2] for i in range(len(listdir))[::2]]:
			try:
				run_path1 = os.path.join(data_folder, run_folder1)
				run_path2 = os.path.join(data_folder, run_folder2)
				result = {}
				with open(os.path.join(run_path1, 'twoSettings.txt'), 'r') as f:
					settings = f.read() 
					import re

					pattern = r'(\w+)\s*=\s*\(([\d.]+),\s*([\d.]+)\)'

					matches = re.findall(pattern, settings)

					
					for match in matches:
						key = match[0]
						value1 = float(match[1])
						value2 = float(match[2])
						result[key] = (value1, value2)

					print(result)
				with open(os.path.join(run_path2, 'twoSettings.txt'), 'r') as f:
					pass
					#print(f.readlines())
				
				timestamp = get_timestamp(run_path)
				fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
				
				extracted_values = {
						'pa1': result['pd1'][0],
						'pd1': result['pd1'][1],
						'pa2': result['pd2'][0],
						'pd2': result['pd2'][1],
						'depth_ratio': 1/float(depth_ratio), # ratio between current and std settings
      					'timestamp': timestamp
					}
				depth_ratios_df.append(extracted_values)
				
				print('\n')
			except Exception as e:
					print(traceback.format_exc())
					print(f'Error {e} at {run_folder1, run_folder2}')
	except Exception as e:
		print(f'Error {e}')

	depth_ratios_df = pd.DataFrame(depth_ratios_df)
 
	return depth_ratios_df

def get_rel_scattering(run_path1, run_path2):
	resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
	resultDict2, scat_ratio2 = _load_single_run_rel_scat(run_path2, plot=True)
	
	print(f"scat_ratio 1, (2 inverted) = {scat_ratio1:.3f}, {1/scat_ratio2:.3f}")
	scat_ratio_avg = (scat_ratio1+1/scat_ratio2)/2
	
	Rratio = resultDict1['initMOTR']/resultDict2['initMOTR']
	print(fr"Rratio = {resultDict1['initMOTR']:.3f} / {resultDict2['initMOTR']:.3f} = {Rratio:.3f}")
	depthRatio = np.sqrt(Rratio/scat_ratio_avg)
	
	return resultDict1, resultDict2, depthRatio


def _load_single_run_rel_scat(run_path, plot=False, cache_all=True):
	filename = os.path.join(run_path, 'data.csv')
	settingsname = os.path.join(run_path, 'Settings.txt')
	
	MAT_fit_cache_path = os.path.join(run_path, 'resultDict.txt')
	
	if not os.path.exists(MAT_fit_cache_path) or not cache_all:
		
		try: 
			dh1 = MTdataHost(SAMPLE_RATE)
			dh1.loadCATdata(fileName=filename, settingsName=settingsname)

			dh1.tBaseline = 1
			dh1.tLoad = 2
			dh1.timeLoad = 30
			dh1.tReload = dh1.tLoad + dh1.timeLoad
			dh1.timeReload = 1
			dh1.tCATbackground = dh1.tReload + dh1.timeReload

			dh1.setOffset()
			dh1.setCATtiming()
			dh1.setAllCAT(0.002)

			fit_results = dh1.getResults(run_path, store=True)
			if plot:
				dh1.storeFits(run_path, combined=True, separate=False)
		except Exception as e:
			print(traceback.format_exc())
			print("Fitting ERROR at ", os.path.basename(run_path), '\n')

			with open(MAT_fit_cache_path, 'w') as f:
				f.write(str('MAT fit failed'))
		
	else:
		print("Accessing cached results from :", os.path.basename(run_path))

		fit_results = open(MAT_fit_cache_path, 'r').read()

		if fit_results == 'MAT fit failed':
			print("Failed fit at :", os.path.basename(run_path))
			fit_results = {}

		else:
			fit_results = eval(open(MAT_fit_cache_path, 'r').read())


	
	scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
	fit_results['scat_ratio'] = scat_ratio
 	#scat_ratio = dh1.motSS/(dh1.reloadVolt+dh1.baseVolt - (dh1.CATbackgroundVolt+dh1.noLightBackground))
	
	return fit_results, scat_ratio

def scat_rate(I, delta, gamma=6.065, Is=1.669):
	"""_summary_

	Args:
		I (float): intensity (Mhz)
		delta (float): detuning (Mhz)
		gamma (float, optional): linewidth (Mhz) Defaults to 6.065.
		Is (float, optional): Should be one of 3.576(isotropic), 2.503(pi), 1.669 (sigma+-). Defaults to 1.669.

	Returns:
		_type_: gamma: the scattering rate
	"""
	return gamma*I/(2*Is*(1+I/Is+4*(delta/gamma)**2))

if __name__ == '__main__':
	run_path = r"C:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\CATMeasurements\testPArun9\16-53-10"
	filename = os.path.join(run_path, 'data.csv')
	bkfilename = os.path.join(run_path, 'data_oldPD.csv')
	settingsname = os.path.join(run_path, 'Settings.txt')
	
	dh1 = MTdataHost(SAMPLE_RATE)
	dh1.loadCATdata(fileName=filename, settingsName=settingsname)
	
 	#dh1.CATbackgroundData(bkfilename)
	dh1.setAllCAT(0.002)
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
In [ ]:
MEASURE_FOLDER = os.path.join(EXP_FOLDER, 'testPARunMega10')
df = get_data_frame(MEASURE_FOLDER)
df.dropna(inplace=True)

df_grouped = df.groupby(by='cat_AOM_ampl')
min_ratios = df_grouped['ratio'].min()

groups = dict(list(df_grouped))
dfs = [df for df in groups.values()]
100%|██████████| 247/247 [00:03<00:00, 79.64it/s]
In [ ]:
max_freqs = [384182.5]*15
#max_freqs=[384178.599, 384179.091, 384184.733]
zipped_data = list(zip(dfs, max_freqs))
fig, ax = plt.subplots()
for i, (df, max_freq)  in enumerate(zipped_data[:]):
    data = df.dropna()
    freqs = ((max_freq-PUMP_FREQUENCY)-(data['tempV']-data['tempV'].min())*FREQVSVOLT- (data['currV']-data['currV'].min())*FREQVSCURR)
    ax=plot_spline_fit(ax, x=freqs, y=data['ratio'], yerr=data['ratioErr'],scolor=f'C{i}', mfc=f'C{i}',color=f'C{i}', s=0.0, ms=5, figsize=(10, 10), label=f"CAT Amplituide = { df.iloc[10]['cat_AOM_ampl'] :.2f}", linewidth=2.5)

plt.legend()

plt.savefig(os.path.join(MEASURE_FOLDER, 'lossFeatures.png'))
In [ ]:
MEASURE_FOLDER = os.path.join(EXP_FOLDER, 'testCATrunMega1')
df = get_data_frame(MEASURE_FOLDER)
df.dropna(inplace=True)

df_grouped = df.groupby(by='cat_AOM_ampl')
min_ratios = df_grouped['ratio'].min()

groups = dict(list(df_grouped))
dfs = [df for df in groups.values()]
100%|██████████| 288/288 [10:29<00:00,  2.19s/it]
In [ ]:
max_freqs = [384274.5]*15
#max_freqs=[384178.599, 384179.091, 384184.733]
zipped_data = list(zip(dfs, max_freqs))
fig, ax = plt.subplots()
for i, (df, max_freq)  in enumerate(zipped_data[:]):
    data = df.dropna()
    freqs = ((max_freq-PUMP_FREQUENCY)-(data['tempV']-data['tempV'].min())*FREQVSVOLT- (data['currV']-data['currV'].min())*FREQVSCURR)
    ax=plot_spline_fit(ax, x=freqs, y=data['ratio'], yerr=data['ratioErr'],scolor=f'C{i}', mfc=f'C{i}',color=f'C{i}', s=0.0, ms=5, figsize=(10, 10), label=f"CAT Amplituide = { df.iloc[10]['cat_AOM_ampl'] :.2f}", linewidth=2.5)

plt.legend()

plt.savefig(os.path.join(MEASURE_FOLDER, 'lossFeatures.png'))
In [ ]:
Pmeter = [2.25
,8.6
,18.65
,31.7
,45.8
,60.6
,71.4
,79.7
,86.1
,91.4
,95.7
,99.0
,101.7
,104.3
,106.5
,108.4
,110.2
,112.2
,114.0
,115.3]

pds = [
(-0.0145, 0.022),
(0.0575, 0.026),
(0.1775, 0.034),
(0.334,.044),
(0.512, 0.055),
(0.687, 0.067),
(0.838, 0.077),
(0.946, 0.084),
(1.035, 0.09),
(1.104, 0.094),
(1.156, 0.098),
(1.206, 0.101),
(1.239, 0.103),
(1.271, 0.105),
(1.303, 0.107),
(1.331, 0.109),
(1.357, 0.112),
(1.385, 0.113),
(1.405, 0.115),
(1.43, 0.117)]
In [ ]:
x = np.linspace(0.0, 1.0, 21)[:-1]
fig, ax = plt.subplots()
ax.plot(x, pdCAT, 'bo-', label='PD CAT')
tax = ax.twinx()
tax.plot(x, Pmeter, 'r^-', label='Power (mW)')

ax.grid()
ax.legend(loc='upper left')

tax.spines['left'].set_color('blue')
ax.yaxis.label.set_color('blue')
ax.tick_params(axis='y', colors='blue')


tax.legend(loc='upper right')

tax.spines['right'].set_color('red')
tax.yaxis.label.set_color('red')
tax.tick_params(axis='y', colors='red')
In [ ]:
run_path = r"C:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\CATMeasurements\testPARunMega8\16-22-02"
filename = os.path.join(run_path, 'data.csv')
bkfilename = os.path.join(run_path, 'data_oldPD.csv')
settingsname = os.path.join(run_path, 'Settings.txt')

dh1 = MTdataHost(SAMPLE_RATE)
dh1.loadCATdata(fileName=filename, settingsName=settingsname)
dh1.setAllCAT(0.002)

from scipy.integrate import odeint
from scipy.optimize import curve_fit

def Nprime(N, t, R, Gamma):
    return R - Gamma*N 
def Nprime2(N, t, R, Gamma, beta):
    return R - Gamma*N - beta*N**2

def N(t, R, Gamma, N0):
    Nsol = odeint(Nprime, N0, t, args=(R, Gamma))
    return Nsol.ravel()
def N2(t, R, Gamma, beta, N0):
    Nsol = odeint(Nprime2, N0, t, args=(R, Gamma, beta))
    return Nsol.ravel()

data_t = dh1.loadingTime - dh1.loadingTime.min()
data_N = dh1.loadingVoltage

popt, cov = curve_fit(N, data_t, data_N, [0.1, 0.15, 0.2])


print(f"R = {popt[0]:.3f} +- {cov[0][0]:.3e} \n Gamma = {popt[1]:.3f} +- {cov[1][1]:.3e} \n  N0 = {popt[2]:.3f} +- {cov[2][2]:.3e}")

fitted_values = N(data_t, *popt)
residuals = data_N - fitted_values
t = np.linspace(0, data_t[-1], 1000)

# plt.plot(data_t, data_N, '.',
#          t, N(t, *popt), '-')
# plt.show()

fig1 = plt.figure(2)
frame1 = fig1.add_axes((.1,.3,.8,.6))

plt.plot(data_t,data_N,'.b', label=f'SS Residuals = {np.sum(residuals**2):.3f}') 
plt.plot(t,N(t,*popt),'-r') 
plt.legend()

frame1.set_xticklabels([]) 
plt.grid()

# Residual plot
frame2 = fig1.add_axes((.1,.1,.8,.2))        
plt.plot(data_t,residuals,'or', ms=1)



popt, cov = curve_fit(N2, data_t, data_N, [0.1, 0.15, 0, 0.2])

print(f"R = {popt[0]:.3f} +- {cov[0][0]:.3e} \n Gamma = {popt[1]:.3f} +- {cov[1][1]:.3e}\n beta = {popt[2]:.3f}  +- {cov[2][2]:.3e} \n N0 = {popt[3]:.3} +- {cov[3][3]:.3e}")

fitted_values = N2(data_t, *popt)
residuals = data_N - fitted_values

t = np.linspace(0, data_t[-1], 1000)
# plt.plot(data_t, data_N, '.',
#          t, N2(t, *popt), '-')
# plt.show()


fig1 = plt.figure(1)
frame1 = fig1.add_axes((.1,.3,.8,.6))

plt.plot(data_t,data_N,'.b', label=f'SS Residuals = {np.sum(residuals**2):.3f}') 
plt.plot(t,N2(t,*popt),'-r') 
plt.legend()

frame1.set_xticklabels([]) 
plt.grid()

# Residual plot
frame2 = fig1.add_axes((.1,.1,.8,.2))        
plt.plot(data_t,residuals,'or', ms=1)
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
R = 0.050 +- 1.219e-09 
 Gamma = 0.163 +- 1.356e-08 
  N0 = 0.191 +- 2.679e-09
R = -0.032 +- 1.974e-07 
 Gamma = -0.431 +- 1.050e-05
 beta = 1.067  +- 3.430e-05 
 N0 = 0.199 +- 3.135e-09
Out[ ]:
[<matplotlib.lines.Line2D at 0x1aab1a4ff50>]
In [ ]:
run_path = r"C:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\CATMeasurements\testPARunMega8\16-22-02"
filename = os.path.join(run_path, 'data.csv')
bkfilename = os.path.join(run_path, 'data_oldPD.csv')
settingsname = os.path.join(run_path, 'Settings.txt')

dh1 = MTdataHost(SAMPLE_RATE)
dh1.loadCATdata(fileName=filename, settingsName=settingsname)
dh1.setAllCAT(0.002)

from scipy.integrate import odeint
from scipy.optimize import curve_fit

def Nprime(N, t, R, Gamma):
    return R - Gamma*N 
def Nprime2(N, t, R, Gamma, beta):
    return R - Gamma*N - beta*N**2

def N(t, R, Gamma, N0):
    Nsol = odeint(Nprime, N0, t, args=(R, Gamma))
    return Nsol.ravel()
def N2(t, R, Gamma, beta, N0):
    Nsol = odeint(Nprime2, N0, t, args=(R, Gamma, beta))
    return Nsol.ravel()

data_t = dh1.loadingTime - dh1.loadingTime.min()
data_N = dh1.loadingVoltage

popt, cov = curve_fit(N, data_t, data_N, [dh1.initMOTR, dh1.motR, 0.2])


print(f"R = {popt[0]:.3f} +- {cov[0][0]:.3e} \n Gamma = {popt[1]:.3f} +- {cov[1][1]:.3e} \n  N0 = {popt[2]:.3f} +- {cov[2][2]:.3e}")

fitted_values = N(data_t, *popt)
residuals = data_N - fitted_values
t = np.linspace(0, data_t[-1], 1000)

# plt.plot(data_t, data_N, '.',
#          t, N(t, *popt), '-')
# plt.show()

fig1 = plt.figure(2)
frame1 = fig1.add_axes((.1,.3,.8,.6))

plt.plot(data_t,data_N,'.b', label=f'SS Residuals = {np.sum(residuals**2):.3f}') 
plt.plot(t,N(t,*popt),'-r') 
plt.legend()

frame1.set_xticklabels([]) 
plt.grid()

# Residual plot
frame2 = fig1.add_axes((.1,.1,.8,.2))        
plt.plot(data_t,residuals,'or', ms=1)



popt, cov = curve_fit(N2, data_t, data_N, [dh1.initMOTR, dh1.motR, 0, 0.2])

print(f"R = {popt[0]:.3f} +- {cov[0][0]:.3e} \n Gamma = {popt[1]:.3f} +- {cov[1][1]:.3e}\n beta = {popt[2]:.3f}  +- {cov[2][2]:.3e} \n N0 = {popt[3]:.3} +- {cov[3][3]:.3e}")

fitted_values = N2(data_t, *popt)
residuals = data_N - fitted_values

t = np.linspace(0, data_t[-1], 1000)

fig1 = plt.figure(1)
frame1 = fig1.add_axes((.1,.3,.8,.6))

plt.plot(data_t,data_N,'.b', label=f'SS Residuals = {np.sum(residuals**2):.3f}') 
plt.plot(t,N2(t,*popt),'-r') 
plt.legend()

frame1.set_xticklabels([]) 
plt.grid()

# Residual plot
frame2 = fig1.add_axes((.1,.1,.8,.2))        
plt.plot(data_t,residuals,'or', ms=1)
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
R = 0.050 +- 1.219e-09 
 Gamma = 0.163 +- 1.356e-08 
  N0 = 0.191 +- 2.679e-09
c:\ProgramData\Anaconda3\envs\magpy_env\Lib\site-packages\scipy\integrate\_odepack_py.py:248: ODEintWarning: Excess work done on this call (perhaps wrong Dfun type). Run with full_output = 1 to get quantitative information.
  warnings.warn(warning_msg, ODEintWarning)
R = -0.032 +- 2.131e-07 
 Gamma = -0.431 +- 1.134e-05
 beta = 1.067  +- 3.703e-05 
 N0 = 0.199 +- 3.273e-09
Out[ ]:
[<matplotlib.lines.Line2D at 0x1aab28b9110>]
In [ ]:
run_path = r"C:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\CATMeasurements\testPARunMega8\16-22-02"
filename = os.path.join(run_path, 'data.csv')
bkfilename = os.path.join(run_path, 'data_oldPD.csv')
settingsname = os.path.join(run_path, 'Settings.txt')

dh1 = MTdataHost(SAMPLE_RATE)
dh1.loadCATdata(fileName=filename, settingsName=settingsname)
dh1.setAllCAT(0.002)

from scipy.integrate import odeint
from scipy.optimize import curve_fit

def Nprime(N, t, R, Gamma):
    return R - Gamma*N 
def Nprime2(N, t, R, Gamma, beta):
    return R - Gamma*N - beta*N**2

def N(t, R, Gamma, N0):
    Nsol = odeint(Nprime, N0, t, args=(R, Gamma))
    return Nsol.ravel()
def N2(t, R, Gamma, beta, N0):
    Nsol = odeint(Nprime2, N0, t, args=(R, Gamma, beta))
    return Nsol.ravel()

data_t = dh1.loadingTime - dh1.loadingTime.min()
data_N = dh1.loadingVoltage

popt, cov = curve_fit(N, data_t, data_N, [dh1.initMOTR, dh1.motR, 0.2], full_output=1)


print(f"R = {popt[0]:.3f} +- {cov[0][0]:.3e} \n Gamma = {popt[1]:.3f} +- {cov[1][1]:.3e} \n  N0 = {popt[2]:.3f} +- {cov[2][2]:.3e}")

fitted_values = N(data_t, *popt)
residuals = data_N - fitted_values
t = np.linspace(0, data_t[-1], 1000)

# plt.plot(data_t, data_N, '.',
#          t, N(t, *popt), '-')
# plt.show()

fig1 = plt.figure(2)
frame1 = fig1.add_axes((.1,.3,.8,.6))

plt.plot(data_t,data_N,'.b', label=f'SS Residuals = {np.sum(residuals**2):.3f}') 
plt.plot(t,N(t,*popt),'-r') 
plt.legend()

frame1.set_xticklabels([]) 
plt.grid()

# Residual plot
frame2 = fig1.add_axes((.1,.1,.8,.2))        
plt.plot(data_t,residuals,'or', ms=1)



popt, cov = curve_fit(N2, data_t, data_N, [dh1.initMOTR, dh1.motR, 0, 0.2], full_output=1)

print(f"R = {popt[0]:.3f} +- {cov[0][0]:.3e} \n Gamma = {popt[1]:.3f} +- {cov[1][1]:.3e}\n beta = {popt[2]:.3f}  +- {cov[2][2]:.3e} \n N0 = {popt[3]:.3} +- {cov[3][3]:.3e}")

fitted_values = N2(data_t, *popt)
residuals = data_N - fitted_values

t = np.linspace(0, data_t[-1], 1000)

fig1 = plt.figure(1)
frame1 = fig1.add_axes((.1,.3,.8,.6))

plt.plot(data_t,data_N,'.b', label=f'SS Residuals = {np.sum(residuals**2):.3f}') 
plt.plot(t,N2(t,*popt),'-r') 
plt.legend()

frame1.set_xticklabels([]) 
plt.grid()

# Residual plot
frame2 = fig1.add_axes((.1,.1,.8,.2))        
plt.plot(data_t,residuals,'or', ms=1)
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[30], line 28
     25 data_t = dh1.loadingTime - dh1.loadingTime.min()
     26 data_N = dh1.loadingVoltage
---> 28 popt, cov = curve_fit(N, data_t, data_N, [dh1.initMOTR, dh1.motR, 0.2], full_output=1)
     31 print(f"R = {popt[0]:.3f} +- {cov[0][0]:.3e} \n Gamma = {popt[1]:.3f} +- {cov[1][1]:.3e} \n  N0 = {popt[2]:.3f} +- {cov[2][2]:.3e}")
     33 fitted_values = N(data_t, *popt)

ValueError: too many values to unpack (expected 2)
In [ ]:
run_path = r"C:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\CATMeasurements\testPARunMega8\16-22-02"
filename = os.path.join(run_path, 'data.csv')
bkfilename = os.path.join(run_path, 'data_oldPD.csv')
settingsname = os.path.join(run_path, 'Settings.txt')

dh1 = MTdataHost(SAMPLE_RATE)
dh1.loadCATdata(fileName=filename, settingsName=settingsname)
dh1.setAllCAT(0.002)

from scipy.integrate import odeint
from scipy.optimize import curve_fit

def Nprime(N, t, R, Gamma):
    return R - Gamma*N 
def Nprime2(N, t, R, Gamma, beta):
    return R - Gamma*N - beta*N**2

def N(t, R, Gamma, N0):
    Nsol = odeint(Nprime, N0, t, args=(R, Gamma))
    return Nsol.ravel()
def N2(t, R, Gamma, beta, N0):
    Nsol = odeint(Nprime2, N0, t, args=(R, Gamma, beta))
    return Nsol.ravel()

data_t = dh1.loadingTime - dh1.loadingTime.min()
data_N = dh1.loadingVoltage

popt, cov, infodict, mesg, ier = curve_fit(N, data_t, data_N, [dh1.initMOTR, dh1.motR, 0.2], full_output=1)


print(f"R = {popt[0]:.3f} +- {cov[0][0]:.3e} \n Gamma = {popt[1]:.3f} +- {cov[1][1]:.3e} \n  N0 = {popt[2]:.3f} +- {cov[2][2]:.3e}")

fitted_values = N(data_t, *popt)
residuals = data_N - fitted_values
t = np.linspace(0, data_t[-1], 1000)

# plt.plot(data_t, data_N, '.',
#          t, N(t, *popt), '-')
# plt.show()

fig1 = plt.figure(2)
frame1 = fig1.add_axes((.1,.3,.8,.6))

plt.plot(data_t,data_N,'.b', label=f'SS Residuals = {np.sum(residuals**2):.3f}') 
plt.plot(t,N(t,*popt),'-r') 
plt.legend()

frame1.set_xticklabels([]) 
plt.grid()

# Residual plot
frame2 = fig1.add_axes((.1,.1,.8,.2))        
plt.plot(data_t,residuals,'or', ms=1)



popt, cov, infodict, mesg, ier = curve_fit(N2, data_t, data_N, [dh1.initMOTR, dh1.motR, 0, 0.2], full_output=1)

print(f"R = {popt[0]:.3f} +- {cov[0][0]:.3e} \n Gamma = {popt[1]:.3f} +- {cov[1][1]:.3e}\n beta = {popt[2]:.3f}  +- {cov[2][2]:.3e} \n N0 = {popt[3]:.3} +- {cov[3][3]:.3e}")

fitted_values = N2(data_t, *popt)
residuals = data_N - fitted_values

t = np.linspace(0, data_t[-1], 1000)

fig1 = plt.figure(1)
frame1 = fig1.add_axes((.1,.3,.8,.6))

plt.plot(data_t,data_N,'.b', label=f'SS Residuals = {np.sum(residuals**2):.3f}') 
plt.plot(t,N2(t,*popt),'-r') 
plt.legend()

frame1.set_xticklabels([]) 
plt.grid()

# Residual plot
frame2 = fig1.add_axes((.1,.1,.8,.2))        
plt.plot(data_t,residuals,'or', ms=1)
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
R = 0.050 +- 1.219e-09 
 Gamma = 0.163 +- 1.356e-08 
  N0 = 0.191 +- 2.679e-09
c:\ProgramData\Anaconda3\envs\magpy_env\Lib\site-packages\scipy\integrate\_odepack_py.py:248: ODEintWarning: Excess work done on this call (perhaps wrong Dfun type). Run with full_output = 1 to get quantitative information.
  warnings.warn(warning_msg, ODEintWarning)
R = -0.032 +- 2.131e-07 
 Gamma = -0.431 +- 1.134e-05
 beta = 1.067  +- 3.703e-05 
 N0 = 0.199 +- 3.273e-09
Out[ ]:
[<matplotlib.lines.Line2D at 0x1aab8cb3c10>]
In [ ]:
print(infodict, mesg, ier)
{'fvec': array([ 0.00070821,  0.00193474,  0.00102504, ..., -0.02544394,
       -0.02452841, -0.02452841]), 'nfev': 52, 'fjac': array([[-1.58462395e+03,  3.15533535e-07,  6.31067069e-07, ...,
         2.82762792e-03,  2.82762792e-03,  2.82762784e-03],
       [-4.23825001e+01, -1.03452419e+02,  9.66607844e-03, ...,
        -1.18571468e-03, -1.18571486e-03, -1.18571483e-03],
       [ 4.59756793e+02, -3.02799153e+01,  2.24243171e+01, ...,
         1.67003347e-03,  1.67003322e-03,  1.67003478e-03],
       [ 1.34613414e+02, -1.60459935e+01,  1.24005906e+01, ...,
        -1.38909042e-03, -1.38909072e-03, -1.38906873e-03]]), 'ipvt': array([1, 4, 2, 3], dtype=int32), 'qtf': array([-1.63301764e-06, -6.49932071e-07,  1.21157320e-05, -2.05726773e-05])} Both actual and predicted relative reductions in the sum of squares
  are at most 0.000000 1
In [ ]:
run_path = r"C:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\CATMeasurements\testPARunMega8\16-22-02"
filename = os.path.join(run_path, 'data.csv')
bkfilename = os.path.join(run_path, 'data_oldPD.csv')
settingsname = os.path.join(run_path, 'Settings.txt')

dh1 = MTdataHost(SAMPLE_RATE)
dh1.loadCATdata(fileName=filename, settingsName=settingsname)
dh1.setAllCAT(0.002)

from scipy.integrate import odeint
from scipy.optimize import curve_fit

def Nprime(N, t, R, Gamma):
    return R - Gamma*N 
def Nprime2(N, t, R, Gamma, beta):
    return R - Gamma*N - beta*N**2

def N(t, R, Gamma, N0):
    Nsol = odeint(Nprime, N0, t, args=(R, Gamma))
    return Nsol.ravel()
def N2(t, R, Gamma, beta, N0):
    Nsol = odeint(Nprime2, N0, t, args=(R, Gamma, beta))
    return Nsol.ravel()

data_t = dh1.loadingTime - dh1.loadingTime.min()
data_N = dh1.loadingVoltage

popt, cov, infodict, mesg, ier = curve_fit(N, data_t, data_N, [dh1.initMOTR, dh1.motR, 0.2], full_output=1, bounds=(0, np.inf))


print(f"R = {popt[0]:.3f} +- {cov[0][0]:.3e} \n Gamma = {popt[1]:.3f} +- {cov[1][1]:.3e} \n  N0 = {popt[2]:.3f} +- {cov[2][2]:.3e}")

fitted_values = N(data_t, *popt)
residuals = data_N - fitted_values
t = np.linspace(0, data_t[-1], 1000)

# plt.plot(data_t, data_N, '.',
#          t, N(t, *popt), '-')
# plt.show()

fig1 = plt.figure(2)
frame1 = fig1.add_axes((.1,.3,.8,.6))

plt.plot(data_t,data_N,'.b', label=f'SS Residuals = {np.sum(residuals**2):.3f}') 
plt.plot(t,N(t,*popt),'-r') 
plt.legend()

frame1.set_xticklabels([]) 
plt.grid()

# Residual plot
frame2 = fig1.add_axes((.1,.1,.8,.2))        
plt.plot(data_t,residuals,'or', ms=1)



popt, cov, infodict, mesg, ier = curve_fit(N2, data_t, data_N, [dh1.initMOTR, dh1.motR, 0, 0.2], full_output=1, bounds=(0, np.inf))

print(f"R = {popt[0]:.3f} +- {cov[0][0]:.3e} \n Gamma = {popt[1]:.3f} +- {cov[1][1]:.3e}\n beta = {popt[2]:.3f}  +- {cov[2][2]:.3e} \n N0 = {popt[3]:.3} +- {cov[3][3]:.3e}")

fitted_values = N2(data_t, *popt)
residuals = data_N - fitted_values

t = np.linspace(0, data_t[-1], 1000)

fig1 = plt.figure(1)
frame1 = fig1.add_axes((.1,.3,.8,.6))

plt.plot(data_t,data_N,'.b', label=f'SS Residuals = {np.sum(residuals**2):.3f}') 
plt.plot(t,N2(t,*popt),'-r') 
plt.legend()

frame1.set_xticklabels([]) 
plt.grid()

# Residual plot
frame2 = fig1.add_axes((.1,.1,.8,.2))        
plt.plot(data_t,residuals,'or', ms=1)
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
R = 0.050 +- 1.219e-09 
 Gamma = 0.163 +- 1.356e-08 
  N0 = 0.191 +- 2.679e-09
R = 0.028 +- 2.047e-07 
 Gamma = 0.000 +- 1.073e-05
 beta = 0.293  +- 3.464e-05 
 N0 = 0.193 +- 4.400e-09
Out[ ]:
[<matplotlib.lines.Line2D at 0x1aab2874f90>]
In [ ]:
run_path = r"C:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\CATMeasurements\testPARunMega8\16-22-02"
filename = os.path.join(run_path, 'data.csv')
bkfilename = os.path.join(run_path, 'data_oldPD.csv')
settingsname = os.path.join(run_path, 'Settings.txt')

dh1 = MTdataHost(SAMPLE_RATE)
dh1.loadCATdata(fileName=filename, settingsName=settingsname)
dh1.setAllCAT(0.002)

from scipy.integrate import odeint
from scipy.optimize import curve_fit

def Nprime(N, t, R, Gamma):
    return R - Gamma*N 
def Nprime2(N, t, R, Gamma, beta):
    return R - Gamma*N - beta*N**2

def N(t, R, Gamma, N0):
    Nsol = odeint(Nprime, N0, t, args=(R, Gamma))
    return Nsol.ravel()
def N2(t, R, Gamma, beta, N0):
    Nsol = odeint(Nprime2, N0, t, args=(R, Gamma, beta))
    return Nsol.ravel()

data_t = dh1.loadingTime - dh1.loadingTime.min()
data_N = dh1.loadingVoltage

popt, cov, infodict, mesg, ier = curve_fit(N, data_t, data_N, [dh1.initMOTR, dh1.motR, 0.2], full_output=1, bounds=(0, np.inf), sigma=dh1.std)


print(f"R = {popt[0]:.3f} +- {cov[0][0]:.3e} \n Gamma = {popt[1]:.3f} +- {cov[1][1]:.3e} \n  N0 = {popt[2]:.3f} +- {cov[2][2]:.3e}")

fitted_values = N(data_t, *popt)
residuals = data_N - fitted_values
t = np.linspace(0, data_t[-1], 1000)

# plt.plot(data_t, data_N, '.',
#          t, N(t, *popt), '-')
# plt.show()

fig1 = plt.figure(2)
frame1 = fig1.add_axes((.1,.3,.8,.6))

plt.plot(data_t,data_N,'.b', label=f'SS Residuals = {np.sum(residuals**2):.3f}') 
plt.plot(t,N(t,*popt),'-r') 
plt.legend()

frame1.set_xticklabels([]) 
plt.grid()

# Residual plot
frame2 = fig1.add_axes((.1,.1,.8,.2))        
plt.plot(data_t,residuals,'or', ms=1)



popt, cov, infodict, mesg, ier = curve_fit(N2, data_t, data_N, [dh1.initMOTR, dh1.motR, 0, 0.2], full_output=1, bounds=(0, np.inf), sigma=dh1.std)

print(f"R = {popt[0]:.3f} +- {cov[0][0]:.3e} \n Gamma = {popt[1]:.3f} +- {cov[1][1]:.3e}\n beta = {popt[2]:.3f}  +- {cov[2][2]:.3e} \n N0 = {popt[3]:.3} +- {cov[3][3]:.3e}")

fitted_values = N2(data_t, *popt)
residuals = data_N - fitted_values

t = np.linspace(0, data_t[-1], 1000)

fig1 = plt.figure(1)
frame1 = fig1.add_axes((.1,.3,.8,.6))

plt.plot(data_t,data_N,'.b', label=f'SS Residuals = {np.sum(residuals**2):.3f}') 
plt.plot(t,N2(t,*popt),'-r') 
plt.legend()

frame1.set_xticklabels([]) 
plt.grid()

# Residual plot
frame2 = fig1.add_axes((.1,.1,.8,.2))        
plt.plot(data_t,residuals,'or', ms=1)
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[34], line 28
     25 data_t = dh1.loadingTime - dh1.loadingTime.min()
     26 data_N = dh1.loadingVoltage
---> 28 popt, cov, infodict, mesg, ier = curve_fit(N, data_t, data_N, [dh1.initMOTR, dh1.motR, 0.2], full_output=1, bounds=(0, np.inf), sigma=dh1.std)
     31 print(f"R = {popt[0]:.3f} +- {cov[0][0]:.3e} \n Gamma = {popt[1]:.3f} +- {cov[1][1]:.3e} \n  N0 = {popt[2]:.3f} +- {cov[2][2]:.3e}")
     33 fitted_values = N(data_t, *popt)

File c:\ProgramData\Anaconda3\envs\magpy_env\Lib\site-packages\scipy\optimize\_minpack_py.py:838, in curve_fit(f, xdata, ydata, p0, sigma, absolute_sigma, check_finite, bounds, method, jac, full_output, **kwargs)
    <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/scipy/optimize/_minpack_py.py?line=835'>836</a>             raise ValueError("`sigma` must be positive definite.") from e
    <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/scipy/optimize/_minpack_py.py?line=836'>837</a>     else:
--> <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/scipy/optimize/_minpack_py.py?line=837'>838</a>         raise ValueError("`sigma` has incorrect shape.")
    <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/scipy/optimize/_minpack_py.py?line=838'>839</a> else:
    <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/scipy/optimize/_minpack_py.py?line=839'>840</a>     transform = None

ValueError: `sigma` has incorrect shape.
In [ ]:
run_path = r"C:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\CATMeasurements\testPARunMega8\16-22-02"
filename = os.path.join(run_path, 'data.csv')
bkfilename = os.path.join(run_path, 'data_oldPD.csv')
settingsname = os.path.join(run_path, 'Settings.txt')

dh1 = MTdataHost(SAMPLE_RATE)
dh1.loadCATdata(fileName=filename, settingsName=settingsname)
dh1.setAllCAT(0.002)

from scipy.integrate import odeint
from scipy.optimize import curve_fit

def Nprime(N, t, R, Gamma):
    return R - Gamma*N 
def Nprime2(N, t, R, Gamma, beta):
    return R - Gamma*N - beta*N**2

def N(t, R, Gamma, N0):
    Nsol = odeint(Nprime, N0, t, args=(R, Gamma))
    return Nsol.ravel()
def N2(t, R, Gamma, beta, N0):
    Nsol = odeint(Nprime2, N0, t, args=(R, Gamma, beta))
    return Nsol.ravel()

data_t = dh1.loadingTime - dh1.loadingTime.min()
data_N = dh1.loadingVoltage

popt, cov, infodict, mesg, ier = curve_fit(N, data_t, data_N, [dh1.initMOTR, dh1.motR, 0.2], full_output=1, bounds=(0, np.inf), sigma=sigma=dh1.std*np.ones(len(data_N)))


print(f"R = {popt[0]:.3f} +- {cov[0][0]:.3e} \n Gamma = {popt[1]:.3f} +- {cov[1][1]:.3e} \n  N0 = {popt[2]:.3f} +- {cov[2][2]:.3e}")

fitted_values = N(data_t, *popt)
residuals = data_N - fitted_values
t = np.linspace(0, data_t[-1], 1000)

# plt.plot(data_t, data_N, '.',
#          t, N(t, *popt), '-')
# plt.show()

fig1 = plt.figure(2)
frame1 = fig1.add_axes((.1,.3,.8,.6))

plt.plot(data_t,data_N,'.b', label=f'SS Residuals = {np.sum(residuals**2):.3f}') 
plt.plot(t,N(t,*popt),'-r') 
plt.legend()

frame1.set_xticklabels([]) 
plt.grid()

# Residual plot
frame2 = fig1.add_axes((.1,.1,.8,.2))        
plt.plot(data_t,residuals,'or', ms=1)



popt, cov, infodict, mesg, ier = curve_fit(N2, data_t, data_N, [dh1.initMOTR, dh1.motR, 0, 0.2], full_output=1, bounds=(0, np.inf), sigma=dh1.std*np.ones(len(data_N)))

print(f"R = {popt[0]:.3f} +- {cov[0][0]:.3e} \n Gamma = {popt[1]:.3f} +- {cov[1][1]:.3e}\n beta = {popt[2]:.3f}  +- {cov[2][2]:.3e} \n N0 = {popt[3]:.3} +- {cov[3][3]:.3e}")

fitted_values = N2(data_t, *popt)
residuals = data_N - fitted_values

t = np.linspace(0, data_t[-1], 1000)

fig1 = plt.figure(1)
frame1 = fig1.add_axes((.1,.3,.8,.6))

plt.plot(data_t,data_N,'.b', label=f'SS Residuals = {np.sum(residuals**2):.3f}') 
plt.plot(t,N2(t,*popt),'-r') 
plt.legend()

frame1.set_xticklabels([]) 
plt.grid()

# Residual plot
frame2 = fig1.add_axes((.1,.1,.8,.2))        
plt.plot(data_t,residuals,'or', ms=1)
  Cell In[35], line 28
    popt, cov, infodict, mesg, ier = curve_fit(N, data_t, data_N, [dh1.initMOTR, dh1.motR, 0.2], full_output=1, bounds=(0, np.inf), sigma=sigma=dh1.std*np.ones(len(data_N)))
                                                                                                                                               ^
SyntaxError: invalid syntax
In [ ]:
run_path = r"C:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\CATMeasurements\testPARunMega8\16-22-02"
filename = os.path.join(run_path, 'data.csv')
bkfilename = os.path.join(run_path, 'data_oldPD.csv')
settingsname = os.path.join(run_path, 'Settings.txt')

dh1 = MTdataHost(SAMPLE_RATE)
dh1.loadCATdata(fileName=filename, settingsName=settingsname)
dh1.setAllCAT(0.002)

from scipy.integrate import odeint
from scipy.optimize import curve_fit

def Nprime(N, t, R, Gamma):
    return R - Gamma*N 
def Nprime2(N, t, R, Gamma, beta):
    return R - Gamma*N - beta*N**2

def N(t, R, Gamma, N0):
    Nsol = odeint(Nprime, N0, t, args=(R, Gamma))
    return Nsol.ravel()
def N2(t, R, Gamma, beta, N0):
    Nsol = odeint(Nprime2, N0, t, args=(R, Gamma, beta))
    return Nsol.ravel()

data_t = dh1.loadingTime - dh1.loadingTime.min()
data_N = dh1.loadingVoltage

popt, cov, infodict, mesg, ier = curve_fit(N, data_t, data_N, [dh1.initMOTR, dh1.motR, 0.2], full_output=1, bounds=(0, np.inf), sigma=dh1.std*np.ones(len(data_N)))


print(f"R = {popt[0]:.3f} +- {cov[0][0]:.3e} \n Gamma = {popt[1]:.3f} +- {cov[1][1]:.3e} \n  N0 = {popt[2]:.3f} +- {cov[2][2]:.3e}")

fitted_values = N(data_t, *popt)
residuals = data_N - fitted_values
t = np.linspace(0, data_t[-1], 1000)

# plt.plot(data_t, data_N, '.',
#          t, N(t, *popt), '-')
# plt.show()

fig1 = plt.figure(2)
frame1 = fig1.add_axes((.1,.3,.8,.6))

plt.plot(data_t,data_N,'.b', label=f'SS Residuals = {np.sum(residuals**2):.3f}') 
plt.plot(t,N(t,*popt),'-r') 
plt.legend()

frame1.set_xticklabels([]) 
plt.grid()

# Residual plot
frame2 = fig1.add_axes((.1,.1,.8,.2))        
plt.plot(data_t,residuals,'or', ms=1)



popt, cov, infodict, mesg, ier = curve_fit(N2, data_t, data_N, [dh1.initMOTR, dh1.motR, 0, 0.2], full_output=1, bounds=(0, np.inf), sigma=dh1.std*np.ones(len(data_N)))

print(f"R = {popt[0]:.3f} +- {cov[0][0]:.3e} \n Gamma = {popt[1]:.3f} +- {cov[1][1]:.3e}\n beta = {popt[2]:.3f}  +- {cov[2][2]:.3e} \n N0 = {popt[3]:.3} +- {cov[3][3]:.3e}")

fitted_values = N2(data_t, *popt)
residuals = data_N - fitted_values

t = np.linspace(0, data_t[-1], 1000)

fig1 = plt.figure(1)
frame1 = fig1.add_axes((.1,.3,.8,.6))

plt.plot(data_t,data_N,'.b', label=f'SS Residuals = {np.sum(residuals**2):.3f}') 
plt.plot(t,N2(t,*popt),'-r') 
plt.legend()

frame1.set_xticklabels([]) 
plt.grid()

# Residual plot
frame2 = fig1.add_axes((.1,.1,.8,.2))        
plt.plot(data_t,residuals,'or', ms=1)
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
R = 0.050 +- 1.219e-09 
 Gamma = 0.163 +- 1.356e-08 
  N0 = 0.191 +- 2.679e-09
R = 0.028 +- 2.047e-07 
 Gamma = 0.000 +- 1.073e-05
 beta = 0.293  +- 3.464e-05 
 N0 = 0.193 +- 4.400e-09
Out[ ]:
[<matplotlib.lines.Line2D at 0x1aabca61c10>]
In [ ]:
dh1.initMOTR
Out[ ]:
0.013134674829377673
In [ ]:
dh1.initMOTR, dh1.motR
Out[ ]:
(0.013134674829377673, 0.1632647677457613)
In [ ]:
get_rel_scattering_df(r'C:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\CATMeasurements\relScatRate\TrapDepthMap')
{'pd1': (1.85, 84.0), 'pd2': (1.125, 82.4)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112149 is out of bounds for axis 0 with size 68161

Fitting ERROR at  17-56-41 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('17-56-41', '17-57-25')
{'pd1': (1.85, 84.0), 'pd2': (1.125, 80.8)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112165 is out of bounds for axis 0 with size 68161

Fitting ERROR at  17-58-10 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('17-58-10', '17-58-54')
{'pd1': (1.85, 84.0), 'pd2': (1.125, 86.4)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112171 is out of bounds for axis 0 with size 68169

Fitting ERROR at  17-59-38 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('17-59-38', '18-00-22')
{'pd1': (1.85, 84.0), 'pd2': (1.125, 85.6)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112205 is out of bounds for axis 0 with size 68161

Fitting ERROR at  18-01-06 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('18-01-06', '18-01-50')
{'pd1': (1.85, 84.0), 'pd2': (1.125, 80.0)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112187 is out of bounds for axis 0 with size 68163

Fitting ERROR at  18-02-39 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('18-02-39', '18-03-31')
{'pd1': (1.85, 84.0), 'pd2': (1.125, 84.0)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112138 is out of bounds for axis 0 with size 68183

Fitting ERROR at  18-04-24 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('18-04-24', '18-05-17')
{'pd1': (1.85, 84.0), 'pd2': (1.125, 81.6)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112174 is out of bounds for axis 0 with size 68175

Fitting ERROR at  18-06-11 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('18-06-11', '18-07-04')
{'pd1': (1.85, 84.0), 'pd2': (1.125, 83.2)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112173 is out of bounds for axis 0 with size 68183

Fitting ERROR at  18-07-59 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('18-07-59', '18-08-51')
{'pd1': (1.85, 84.0), 'pd2': (1.125, 88.0)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112098 is out of bounds for axis 0 with size 68171

Fitting ERROR at  18-09-42 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('18-09-42', '18-10-35')
{'pd1': (1.85, 84.0), 'pd2': (1.125, 87.2)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112136 is out of bounds for axis 0 with size 68181

Fitting ERROR at  18-11-29 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('18-11-29', '18-12-22')
{'pd1': (1.85, 84.0), 'pd2': (1.125, 84.8)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112126 is out of bounds for axis 0 with size 68173

Fitting ERROR at  18-13-17 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('18-13-17', '18-14-10')
{'pd1': (1.85, 84.0), 'pd2': (0.6900000000000001, 82.4)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112205 is out of bounds for axis 0 with size 68177

Fitting ERROR at  18-15-02 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('18-15-02', '18-15-55')
{'pd1': (1.85, 84.0), 'pd2': (0.6900000000000001, 80.8)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112192 is out of bounds for axis 0 with size 68175

Fitting ERROR at  18-16-49 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('18-16-49', '18-17-41')
{'pd1': (1.85, 84.0), 'pd2': (0.6900000000000001, 86.4)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112084 is out of bounds for axis 0 with size 68167

Fitting ERROR at  18-18-33 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('18-18-33', '18-19-25')
{'pd1': (1.85, 84.0), 'pd2': (0.6900000000000001, 85.6)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112177 is out of bounds for axis 0 with size 68173

Fitting ERROR at  18-20-18 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('18-20-18', '18-21-10')
{'pd1': (1.85, 84.0), 'pd2': (0.6900000000000001, 80.0)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112103 is out of bounds for axis 0 with size 68177

Fitting ERROR at  18-22-04 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('18-22-04', '18-22-56')
{'pd1': (1.85, 84.0), 'pd2': (0.6900000000000001, 84.0)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112145 is out of bounds for axis 0 with size 68183

Fitting ERROR at  18-23-50 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('18-23-50', '18-24-46')
{'pd1': (1.85, 84.0), 'pd2': (0.6900000000000001, 81.6)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112160 is out of bounds for axis 0 with size 68171

Fitting ERROR at  18-25-41 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('18-25-41', '18-26-35')
{'pd1': (1.85, 84.0), 'pd2': (0.6900000000000001, 83.2)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112190 is out of bounds for axis 0 with size 68183

Fitting ERROR at  18-27-30 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('18-27-30', '18-28-23')
{'pd1': (1.85, 84.0), 'pd2': (0.6900000000000001, 88.0)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112110 is out of bounds for axis 0 with size 68175

Fitting ERROR at  18-29-14 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('18-29-14', '18-30-07')
{'pd1': (1.85, 84.0), 'pd2': (0.6900000000000001, 87.2)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112140 is out of bounds for axis 0 with size 68175

Fitting ERROR at  18-30-58 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('18-30-58', '18-31-50')
{'pd1': (1.85, 84.0), 'pd2': (0.6900000000000001, 84.8)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112149 is out of bounds for axis 0 with size 68169

Fitting ERROR at  18-32-43 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('18-32-43', '18-33-33')
{'pd1': (1.85, 84.0), 'pd2': (1.705, 82.4)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112198 is out of bounds for axis 0 with size 68161

Fitting ERROR at  18-34-17 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('18-34-17', '18-35-01')
{'pd1': (1.85, 84.0), 'pd2': (1.705, 80.8)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112141 is out of bounds for axis 0 with size 68161

Fitting ERROR at  18-35-45 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('18-35-45', '18-36-37')
{'pd1': (1.85, 84.0), 'pd2': (1.705, 86.4)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112206 is out of bounds for axis 0 with size 68169

Fitting ERROR at  18-37-28 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('18-37-28', '18-38-22')
{'pd1': (1.85, 84.0), 'pd2': (1.705, 85.6)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112134 is out of bounds for axis 0 with size 68171

Fitting ERROR at  18-39-14 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('18-39-14', '18-40-07')
{'pd1': (1.85, 84.0), 'pd2': (1.705, 80.0)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112207 is out of bounds for axis 0 with size 68187

Fitting ERROR at  18-41-02 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('18-41-02', '18-41-55')
{'pd1': (1.85, 84.0), 'pd2': (1.705, 84.0)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112086 is out of bounds for axis 0 with size 68181

Fitting ERROR at  18-42-50 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('18-42-50', '18-43-45')
{'pd1': (1.85, 84.0), 'pd2': (1.705, 81.6)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112204 is out of bounds for axis 0 with size 68187

Fitting ERROR at  18-44-38 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('18-44-38', '18-45-32')
{'pd1': (1.85, 84.0), 'pd2': (1.705, 83.2)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112138 is out of bounds for axis 0 with size 68169

Fitting ERROR at  18-46-25 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('18-46-25', '18-47-18')
{'pd1': (1.85, 84.0), 'pd2': (1.705, 88.0)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112126 is out of bounds for axis 0 with size 68187

Fitting ERROR at  18-48-12 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('18-48-12', '18-49-06')
{'pd1': (1.85, 84.0), 'pd2': (1.705, 87.2)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112147 is out of bounds for axis 0 with size 68181

Fitting ERROR at  18-50-01 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('18-50-01', '18-50-54')
{'pd1': (1.85, 84.0), 'pd2': (1.705, 84.8)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112133 is out of bounds for axis 0 with size 68169

Fitting ERROR at  18-51-46 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('18-51-46', '18-52-38')
{'pd1': (1.85, 84.0), 'pd2': (0.4, 82.4)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112171 is out of bounds for axis 0 with size 68171

Fitting ERROR at  18-53-31 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('18-53-31', '18-54-26')
{'pd1': (1.85, 84.0), 'pd2': (0.4, 80.8)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112112 is out of bounds for axis 0 with size 68183

Fitting ERROR at  18-55-20 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('18-55-20', '18-56-14')
{'pd1': (1.85, 84.0), 'pd2': (0.4, 86.4)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112187 is out of bounds for axis 0 with size 68185

Fitting ERROR at  18-57-09 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('18-57-09', '18-58-04')
{'pd1': (1.85, 84.0), 'pd2': (0.4, 85.6)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112092 is out of bounds for axis 0 with size 68175

Fitting ERROR at  18-58-58 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('18-58-58', '18-59-53')
{'pd1': (1.85, 84.0), 'pd2': (0.4, 80.0)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112143 is out of bounds for axis 0 with size 68175

Fitting ERROR at  19-00-50 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('19-00-50', '19-01-45')
{'pd1': (1.85, 84.0), 'pd2': (0.4, 84.0)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112093 is out of bounds for axis 0 with size 68171

Fitting ERROR at  19-02-37 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('19-02-37', '19-03-30')
{'pd1': (1.85, 84.0), 'pd2': (0.4, 81.6)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112099 is out of bounds for axis 0 with size 68169

Fitting ERROR at  19-04-25 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('19-04-25', '19-05-18')
{'pd1': (1.85, 84.0), 'pd2': (0.4, 83.2)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112171 is out of bounds for axis 0 with size 68167

Fitting ERROR at  19-06-09 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('19-06-09', '19-07-03')
{'pd1': (1.85, 84.0), 'pd2': (0.4, 88.0)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112160 is out of bounds for axis 0 with size 68171

Fitting ERROR at  19-07-58 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('19-07-58', '19-08-50')
{'pd1': (1.85, 84.0), 'pd2': (0.4, 87.2)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112133 is out of bounds for axis 0 with size 68177

Fitting ERROR at  19-09-45 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('19-09-45', '19-10-40')
{'pd1': (1.85, 84.0), 'pd2': (0.4, 84.8)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112187 is out of bounds for axis 0 with size 68173

Fitting ERROR at  19-11-33 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('19-11-33', '19-12-26')
{'pd1': (1.85, 84.0), 'pd2': (0.9800000000000001, 82.4)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112114 is out of bounds for axis 0 with size 68171

Fitting ERROR at  19-13-21 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('19-13-21', '19-14-14')
{'pd1': (1.85, 84.0), 'pd2': (0.9800000000000001, 80.8)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112131 is out of bounds for axis 0 with size 68167

Fitting ERROR at  19-15-07 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('19-15-07', '19-15-58')
{'pd1': (1.85, 84.0), 'pd2': (0.9800000000000001, 86.4)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112105 is out of bounds for axis 0 with size 68177

Fitting ERROR at  19-16-53 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('19-16-53', '19-17-45')
{'pd1': (1.85, 84.0), 'pd2': (0.9800000000000001, 85.6)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112155 is out of bounds for axis 0 with size 68173

Fitting ERROR at  19-18-39 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('19-18-39', '19-19-32')
{'pd1': (1.85, 84.0), 'pd2': (0.9800000000000001, 80.0)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112146 is out of bounds for axis 0 with size 68177

Fitting ERROR at  19-20-25 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('19-20-25', '19-21-18')
{'pd1': (1.85, 84.0), 'pd2': (0.9800000000000001, 84.0)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112179 is out of bounds for axis 0 with size 68177

Fitting ERROR at  19-22-11 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('19-22-11', '19-23-06')
{'pd1': (1.85, 84.0), 'pd2': (0.9800000000000001, 81.6)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112104 is out of bounds for axis 0 with size 68169

Fitting ERROR at  19-23-58 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('19-23-58', '19-24-50')
{'pd1': (1.85, 84.0), 'pd2': (0.9800000000000001, 83.2)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112115 is out of bounds for axis 0 with size 68169

Fitting ERROR at  19-25-42 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('19-25-42', '19-26-32')
{'pd1': (1.85, 84.0), 'pd2': (0.9800000000000001, 88.0)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112189 is out of bounds for axis 0 with size 68185

Fitting ERROR at  19-27-24 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('19-27-24', '19-28-17')
{'pd1': (1.85, 84.0), 'pd2': (0.9800000000000001, 87.2)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112102 is out of bounds for axis 0 with size 68167

Fitting ERROR at  19-29-10 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('19-29-10', '19-30-04')
{'pd1': (1.85, 84.0), 'pd2': (0.9800000000000001, 84.8)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112128 is out of bounds for axis 0 with size 68169

Fitting ERROR at  19-30-56 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('19-30-56', '19-31-49')
{'pd1': (1.85, 84.0), 'pd2': (0.8350000000000001, 82.4)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112201 is out of bounds for axis 0 with size 68167

Fitting ERROR at  19-32-43 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('19-32-43', '19-33-39')
{'pd1': (1.85, 84.0), 'pd2': (0.8350000000000001, 80.8)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112179 is out of bounds for axis 0 with size 68177

Fitting ERROR at  19-34-31 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('19-34-31', '19-35-25')
{'pd1': (1.85, 84.0), 'pd2': (0.8350000000000001, 86.4)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112104 is out of bounds for axis 0 with size 68181

Fitting ERROR at  19-36-19 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('19-36-19', '19-37-13')
{'pd1': (1.85, 84.0), 'pd2': (0.8350000000000001, 85.6)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112163 is out of bounds for axis 0 with size 68179

Fitting ERROR at  19-38-05 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('19-38-05', '19-38-59')
{'pd1': (1.85, 84.0), 'pd2': (0.8350000000000001, 80.0)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112171 is out of bounds for axis 0 with size 68169

Fitting ERROR at  19-39-54 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('19-39-54', '19-40-47')
{'pd1': (1.85, 84.0), 'pd2': (0.8350000000000001, 84.0)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112140 is out of bounds for axis 0 with size 68177

Fitting ERROR at  19-41-43 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('19-41-43', '19-42-38')
{'pd1': (1.85, 84.0), 'pd2': (0.8350000000000001, 81.6)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112175 is out of bounds for axis 0 with size 68183

Fitting ERROR at  19-43-34 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('19-43-34', '19-44-27')
{'pd1': (1.85, 84.0), 'pd2': (0.8350000000000001, 83.2)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112091 is out of bounds for axis 0 with size 68175

Fitting ERROR at  19-45-18 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('19-45-18', '19-46-12')
{'pd1': (1.85, 84.0), 'pd2': (0.8350000000000001, 88.0)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112125 is out of bounds for axis 0 with size 68177

Fitting ERROR at  19-47-08 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('19-47-08', '19-48-02')
{'pd1': (1.85, 84.0), 'pd2': (0.8350000000000001, 87.2)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112091 is out of bounds for axis 0 with size 68169

Fitting ERROR at  19-48-55 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('19-48-55', '19-49-51')
{'pd1': (1.85, 84.0), 'pd2': (0.8350000000000001, 84.8)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112201 is out of bounds for axis 0 with size 68173

Fitting ERROR at  19-50-43 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('19-50-43', '19-51-37')
{'pd1': (1.85, 84.0), 'pd2': (1.415, 82.4)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112184 is out of bounds for axis 0 with size 68179

Fitting ERROR at  19-52-32 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('19-52-32', '19-53-26')
{'pd1': (1.85, 84.0), 'pd2': (1.415, 80.8)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112205 is out of bounds for axis 0 with size 68165

Fitting ERROR at  19-54-20 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('19-54-20', '19-55-13')
{'pd1': (1.85, 84.0), 'pd2': (1.415, 86.4)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112160 is out of bounds for axis 0 with size 68181

Fitting ERROR at  19-56-07 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('19-56-07', '19-57-02')
{'pd1': (1.85, 84.0), 'pd2': (1.415, 85.6)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112174 is out of bounds for axis 0 with size 68177

Fitting ERROR at  19-57-56 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('19-57-56', '19-58-49')
{'pd1': (1.85, 84.0), 'pd2': (1.415, 80.0)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112151 is out of bounds for axis 0 with size 68175

Fitting ERROR at  19-59-43 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('19-59-43', '20-00-35')
{'pd1': (1.85, 84.0), 'pd2': (1.415, 84.0)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112212 is out of bounds for axis 0 with size 68179

Fitting ERROR at  20-01-27 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('20-01-27', '20-02-23')
{'pd1': (1.85, 84.0), 'pd2': (1.415, 81.6)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112141 is out of bounds for axis 0 with size 68177

Fitting ERROR at  20-03-16 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('20-03-16', '20-04-08')
{'pd1': (1.85, 84.0), 'pd2': (1.415, 83.2)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112178 is out of bounds for axis 0 with size 68163

Fitting ERROR at  20-05-01 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('20-05-01', '20-05-44')
{'pd1': (1.85, 84.0), 'pd2': (1.415, 88.0)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112162 is out of bounds for axis 0 with size 68163

Fitting ERROR at  20-06-28 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('20-06-28', '20-07-12')
{'pd1': (1.85, 84.0), 'pd2': (1.415, 87.2)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112196 is out of bounds for axis 0 with size 68161

Fitting ERROR at  20-07-55 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('20-07-55', '20-08-39')
{'pd1': (1.85, 84.0), 'pd2': (1.415, 84.8)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112138 is out of bounds for axis 0 with size 68161

Fitting ERROR at  20-09-22 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('20-09-22', '20-10-06')
{'pd1': (1.85, 84.0), 'pd2': (0.545, 82.4)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112186 is out of bounds for axis 0 with size 68161

Fitting ERROR at  20-10-49 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('20-10-49', '20-11-33')
{'pd1': (1.85, 84.0), 'pd2': (0.545, 80.8)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112105 is out of bounds for axis 0 with size 68161

Fitting ERROR at  20-12-17 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('20-12-17', '20-13-01')
{'pd1': (1.85, 84.0), 'pd2': (0.545, 86.4)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112196 is out of bounds for axis 0 with size 68161

Fitting ERROR at  20-13-44 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('20-13-44', '20-14-28')
{'pd1': (1.85, 84.0), 'pd2': (0.545, 85.6)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112123 is out of bounds for axis 0 with size 68159

Fitting ERROR at  20-15-12 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('20-15-12', '20-15-55')
{'pd1': (1.85, 84.0), 'pd2': (0.545, 80.0)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112131 is out of bounds for axis 0 with size 68163

Fitting ERROR at  20-16-39 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('20-16-39', '20-17-24')
{'pd1': (1.85, 84.0), 'pd2': (0.545, 84.0)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112139 is out of bounds for axis 0 with size 68163

Fitting ERROR at  20-18-07 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('20-18-07', '20-18-51')
{'pd1': (1.85, 84.0), 'pd2': (0.545, 81.6)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112090 is out of bounds for axis 0 with size 68173

Fitting ERROR at  20-19-35 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('20-19-35', '20-20-19')
{'pd1': (1.85, 84.0), 'pd2': (0.545, 83.2)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112122 is out of bounds for axis 0 with size 68167

Fitting ERROR at  20-21-02 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('20-21-02', '20-21-47')
{'pd1': (1.85, 84.0), 'pd2': (0.545, 88.0)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112152 is out of bounds for axis 0 with size 68227

Fitting ERROR at  20-22-32 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('20-22-32', '20-23-18')
{'pd1': (1.85, 84.0), 'pd2': (0.545, 87.2)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112153 is out of bounds for axis 0 with size 68167

Fitting ERROR at  20-24-04 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('20-24-04', '20-24-50')
{'pd1': (1.85, 84.0), 'pd2': (0.545, 84.8)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112189 is out of bounds for axis 0 with size 68161

Fitting ERROR at  20-25-34 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('20-25-34', '20-26-20')
{'pd1': (1.85, 84.0), 'pd2': (1.27, 82.4)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112179 is out of bounds for axis 0 with size 68163

Fitting ERROR at  20-27-05 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('20-27-05', '20-27-51')
{'pd1': (1.85, 84.0), 'pd2': (1.27, 80.8)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112093 is out of bounds for axis 0 with size 68161

Fitting ERROR at  20-28-39 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('20-28-39', '20-29-29')
{'pd1': (1.85, 84.0), 'pd2': (1.27, 86.4)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112134 is out of bounds for axis 0 with size 68193

Fitting ERROR at  20-30-22 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('20-30-22', '20-31-20')
{'pd1': (1.85, 84.0), 'pd2': (1.27, 85.6)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112213 is out of bounds for axis 0 with size 68183

Fitting ERROR at  20-32-12 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('20-32-12', '20-33-07')
{'pd1': (1.85, 84.0), 'pd2': (1.27, 80.0)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112176 is out of bounds for axis 0 with size 68171

Fitting ERROR at  20-33-57 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('20-33-57', '20-34-48')
{'pd1': (1.85, 84.0), 'pd2': (1.27, 84.0)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112112 is out of bounds for axis 0 with size 68173

Fitting ERROR at  20-35-41 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('20-35-41', '20-36-35')
{'pd1': (1.85, 84.0), 'pd2': (1.27, 81.6)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112186 is out of bounds for axis 0 with size 68179

Fitting ERROR at  20-37-26 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('20-37-26', '20-38-18')
{'pd1': (1.85, 84.0), 'pd2': (1.27, 83.2)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112117 is out of bounds for axis 0 with size 68169

Fitting ERROR at  20-39-08 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('20-39-08', '20-39-58')
{'pd1': (1.85, 84.0), 'pd2': (1.27, 88.0)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112191 is out of bounds for axis 0 with size 68171

Fitting ERROR at  20-40-50 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('20-40-50', '20-41-42')
{'pd1': (1.85, 84.0), 'pd2': (1.27, 87.2)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112123 is out of bounds for axis 0 with size 68169

Fitting ERROR at  20-42-28 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('20-42-28', '20-43-15')
{'pd1': (1.85, 84.0), 'pd2': (1.27, 84.8)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112133 is out of bounds for axis 0 with size 68161

Fitting ERROR at  20-44-02 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('20-44-02', '20-44-50')
{'pd1': (1.85, 84.0), 'pd2': (1.56, 82.4)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112104 is out of bounds for axis 0 with size 68169

Fitting ERROR at  20-45-40 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('20-45-40', '20-46-29')
{'pd1': (1.85, 84.0), 'pd2': (1.56, 80.8)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112102 is out of bounds for axis 0 with size 68169

Fitting ERROR at  20-47-19 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('20-47-19', '20-48-09')
{'pd1': (1.85, 84.0), 'pd2': (1.56, 86.4)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112204 is out of bounds for axis 0 with size 68169

Fitting ERROR at  20-49-00 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('20-49-00', '20-49-52')
{'pd1': (1.85, 84.0), 'pd2': (1.56, 85.6)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112149 is out of bounds for axis 0 with size 68169

Fitting ERROR at  20-50-43 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('20-50-43', '20-51-33')
{'pd1': (1.85, 84.0), 'pd2': (1.56, 80.0)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112126 is out of bounds for axis 0 with size 68163

Fitting ERROR at  20-52-23 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('20-52-23', '20-53-13')
{'pd1': (1.85, 84.0), 'pd2': (1.56, 84.0)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112148 is out of bounds for axis 0 with size 68177

Fitting ERROR at  20-54-03 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('20-54-03', '20-54-56')
{'pd1': (1.85, 84.0), 'pd2': (1.56, 81.6)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112096 is out of bounds for axis 0 with size 68171

Fitting ERROR at  20-55-47 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('20-55-47', '20-56-40')
{'pd1': (1.85, 84.0), 'pd2': (1.56, 83.2)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112101 is out of bounds for axis 0 with size 68175

Fitting ERROR at  20-57-31 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('20-57-31', '20-58-23')
{'pd1': (1.85, 84.0), 'pd2': (1.56, 88.0)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112170 is out of bounds for axis 0 with size 68167

Fitting ERROR at  20-59-12 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('20-59-12', '20-59-57')
{'pd1': (1.85, 84.0), 'pd2': (1.56, 87.2)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112155 is out of bounds for axis 0 with size 68163

Fitting ERROR at  21-00-42 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('21-00-42', '21-01-27')
{'pd1': (1.85, 84.0), 'pd2': (1.56, 84.8)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112124 is out of bounds for axis 0 with size 68161

Fitting ERROR at  21-02-12 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('21-02-12', '21-02-56')
{'pd1': (1.85, 84.0), 'pd2': (1.85, 82.4)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112137 is out of bounds for axis 0 with size 68161

Fitting ERROR at  21-03-41 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('21-03-41', '21-04-25')
{'pd1': (1.85, 84.0), 'pd2': (1.85, 80.8)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112186 is out of bounds for axis 0 with size 68157

Fitting ERROR at  21-05-09 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('21-05-09', '21-05-53')
{'pd1': (1.85, 84.0), 'pd2': (1.85, 86.4)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112097 is out of bounds for axis 0 with size 68159

Fitting ERROR at  21-06-37 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('21-06-37', '21-07-20')
{'pd1': (1.85, 84.0), 'pd2': (1.85, 85.6)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112165 is out of bounds for axis 0 with size 68163

Fitting ERROR at  21-08-04 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('21-08-04', '21-08-57')
{'pd1': (1.85, 84.0), 'pd2': (1.85, 80.0)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112206 is out of bounds for axis 0 with size 68161

Fitting ERROR at  21-09-50 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('21-09-50', '21-10-43')
{'pd1': (1.85, 84.0), 'pd2': (1.85, 84.0)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112206 is out of bounds for axis 0 with size 68167

Fitting ERROR at  21-11-36 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('21-11-36', '21-12-29')
{'pd1': (1.85, 84.0), 'pd2': (1.85, 81.6)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112175 is out of bounds for axis 0 with size 68161

Fitting ERROR at  21-13-13 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('21-13-13', '21-13-57')
{'pd1': (1.85, 84.0), 'pd2': (1.85, 83.2)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112086 is out of bounds for axis 0 with size 68161

Fitting ERROR at  21-14-41 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('21-14-41', '21-15-24')
{'pd1': (1.85, 84.0), 'pd2': (1.85, 88.0)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112175 is out of bounds for axis 0 with size 68161

Fitting ERROR at  21-16-08 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('21-16-08', '21-16-52')
{'pd1': (1.85, 84.0), 'pd2': (1.85, 87.2)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112122 is out of bounds for axis 0 with size 68165

Fitting ERROR at  21-17-36 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('21-17-36', '21-18-19')
{'pd1': (1.85, 84.0), 'pd2': (1.85, 84.8)}
Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112084 is out of bounds for axis 0 with size 68161

Fitting ERROR at  21-19-03 

Traceback (most recent call last):
  File "<ipython-input-1-b42cbb4ac10c>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-1-b42cbb4ac10c>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'fit_results' where it is not associated with a value

Error cannot access local variable 'fit_results' where it is not associated with a value at ('21-19-03', '21-19-47')
Out[ ]:
In [ ]:
import os
import sys
from functools import partial
sys.path.append(os.path.join(os.getcwd(), '..')) #adds directory below as valid path
from  datetime import datetime, timedelta
dateformat = "%H-%M-%S"
from collections import deque
import traceback
from multiprocessing import Pool
from tqdm import tqdm

import scipy.constants as spc
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd

plt.rcParams['axes.grid'] = True
plt.rcParams['grid.linestyle'] = '--'

from MT_class_PID_new import MTdataHost
from global_folder.myplotsty import *
from global_folder.my_helpers import *

PUMP_FREQUENCY = 384228.6
REPUMP_FREQUENCY = 384228.6 + 6.56
SAMPLE_RATE = 2000
FREQVSVOLT = 221.0 
FREQVSCURR = 1.13

# TODO: find a better place for this
EXP_FOLDER =r'C:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\CATMeasurements'
MEASURE_FOLDER = os.path.join(EXP_FOLDER, 'testPArun16')
WDATA_FOLDER =os.path.join(MEASURE_FOLDER, 'testPArun16.csv')

# TODO: maybe make a run analysis class out of this?
def dump():
	fig, ax = plt.subplots()
	plot_results(ax, df, max_freq= 384219., fmt='o', mfc='red', save_folder=MEASURE_FOLDER)
	plt.savefig(os.path.join(MEASURE_FOLDER, 'ratio_vs_freq.png'))

	
	collect_plots(MEASURE_FOLDER, os.path.join(MEASURE_FOLDER, 'collected_plots'), 'deloadPhase.png')
 
	#*-----------------------
	#* SINGLE RUN
 	#*----------------------- 
  
	MEASURE_FOLDER = os.path.join(EXP_FOLDER, 'testPArun9')
	df = get_data_frame(MEASURE_FOLDER)
	df.dropna(inplace=True)
	#freqs = plot_results(df, 384201., save_folder=MEASURE_FOLDER)
 
	data = df.dropna()
	freqs = ((384201-PUMP_FREQUENCY)-(data['tempV']-df['tempV'].min())*FREQVSVOLT- (data['currV']-df['currV'].min())*FREQVSCURR)
	fig, ax = plt.subplots()
	plot_spline_fit(ax=ax, x=freqs, y=data['ratio'], yerr=data['ratioErr'], 
				 s=0.1, save_folder=MEASURE_FOLDER, 
				 mfc='red', color='black', 
				 title='Trap Depth = 1.99 K')
 
	# *-----------------------
	# * MULTIPLE RUN COMPARISON
 	# *-----------------------
	folders = [os.path.join(EXP_FOLDER, path ) for path in ['testPARun11', 'testPARun12', 'testPARun13', 'testPARun14']]
	dfs = [get_data_frame(measure_folder, cache_all=True) for measure_folder in folders]

	colors = ['red', 'dodgerblue', 'green', 'grey']
	max_freqs = [384178.881, 384178.593,384179.068, 384184.731]
	#max_freqs=[384178.599, 384179.091, 384184.733]

	zipped_data = list(zip(dfs, max_freqs))
	fig, ax = plt.subplots()
	for i, (df, max_freq)  in enumerate(zipped_data[:3]):
		data = df.dropna()
		freqs = ((max_freq-PUMP_FREQUENCY)-(data['tempV']-data['tempV'].min())*FREQVSVOLT- (data['currV']-data['currV'].min())*FREQVSCURR)
		color = colors[i]
		ax=plot_spline_fit(ax, x=freqs, y=data['ratio'], scolor=color, mfc=color,color=color, s=0.02, ms=5)

	#*-----------------------
	#* PARSING WAVEMETER DATA
 	#*-----------------------

	MEASURE_FOLDER = os.path.join(EXP_FOLDER, 'testPArun14')
	WDATA_FOLDER =os.path.join(MEASURE_FOLDER, 'testPArun14.csv')
	freq_data, max_freq, min_freq = add_wavemeter_data('', WDATA_FOLDER)
	data = freq_data[:]
	levels = staircase_fit(data)

	data = get_data_frame(MEASURE_FOLDER)
	data.dropna(inplace=True)
	freqs = ((max_freq)-(data['tempV']-data['tempV'].min())*FREQVSVOLT- (data['currV']-data['currV'].min())*FREQVSCURR)
	plt.plot(freqs)
 
	#*-----------------------
	#* GETTING DEPTH_RATIO DATAFRAME
 	#*-----------------------
	MEASURE_FOLDER = r'C:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\CATMeasurements\relScatRate'
	depth_ratios_df = get_rel_scattering_df(MEASURE_FOLDER)
	df_slice = depth_ratios_df[(depth_ratios_df['pa1']==1.85) & (depth_ratios_df['pd1']==84) & (depth_ratios_df['pd2'] == 84)]
	x = df_slice['pa2']
	y = df_slice['depth_ratio']
	plt.plot(x,y, 'o')

	#*-----------------------
	#* MEGA_RUN
 	#*-----------------------	
	MEASURE_FOLDER = os.path.join(EXP_FOLDER, 'testPARunMega')
	df = get_data_frame(MEASURE_FOLDER)
	df.dropna(inplace=True)

	df_grouped = df.groupby(by='pump_reference')
	min_ratios = df_grouped['ratio'].min()

	groups = dict(list(df_grouped))
	dfs = [df for df in groups.values()]
 
	max_freqs = [384182.5]*15
	#max_freqs=[384178.599, 384179.091, 384184.733]
	zipped_data = list(zip(dfs, max_freqs))
	fig, ax = plt.subplots()
	for i, (df, max_freq)  in enumerate(zipped_data[:]):
		data = df.dropna()
		freqs = ((max_freq-PUMP_FREQUENCY)-(data['tempV']-data['tempV'].min())*FREQVSVOLT- (data['currV']-data['currV'].min())*FREQVSCURR)
		ax=plot_spline_fit(ax, x=freqs, y=data['ratio'], yerr=data['ratioErr'],scolor=f'C{i}', mfc=f'C{i}',color=f'C{i}', s=0.0, ms=5, figsize=(10, 10), label=f"Pump Amplituide = { df.iloc[10]['pump_reference'] :.2f}", linewidth=2.5)

	plt.legend()

	plt.savefig(os.path.join(MEASURE_FOLDER, 'lossFeatures.png'))
	#*-----------------------
	#* MULTIPLE MEGARUN
	#*-----------------------
 
	folders = [os.path.join(EXP_FOLDER, path ) for path in ['testPArunMega', 'testPArunMega2']]
	dfs_mega = [get_data_frame(measure_folder, cache_all=True).dropna() for measure_folder in folders]

	dfs_grouped = [df_mega.groupby(by='pump_reference') for df_mega in dfs_mega]
	min_ratios = [df_grouped['ratio'].min() for df_grouped in dfs_grouped]

	groupss = [dict(list(df_grouped)) for df_grouped in dfs_grouped]
	dfs = [ [df for df in groups.values()] for groups in groupss]
 
	for row in dfs:
		x = [df['pump_reference'].mean() for df in row]
		y = [(df['ratio'].max() - df['ratio'].min())/df['motSS'].std() for df in row]
		plt.plot( x, y ,'-o', label=fr"$\delta$ = {180 - 2*row[0]['pump_AOM_freq'].mean()} MHz")
		plt.xlabel('Pump Amplitude')
		plt.ylabel(r'SNR $ = \frac{V_{ss, off} - V_{ss, on}}{\sigma_{V,off}}$ ')
	plt.legend()

def freq_misc():
	WDATA_FOLDER = r'C:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\CATMeasurements\CATcurrTestrun3.csv'
	freq_data = add_wavemeter_data('', WDATA_FOLDER)
	levels = staircase_fit(freq_data[0], peak_height=0.2, distance=50, data_offset=1, window_size=1) 

	plt.close()
 
	x = np.linspace(0, 4.9, 25)
	y = levels
 
	plt.plot(levels, '-o')
	plt.title('Levels plot')
	
	m, b, fit_line = my_linear_fit(x, y)
def save_fit_results(run_path, plot=False):
	filename = os.path.join(run_path, 'data.csv')
	bkfilename = os.path.join(run_path, 'data_oldPD.csv')
	settingsname = os.path.join(run_path, 'Settings.txt')
	
	dataHost = MTdataHost(SAMPLE_RATE)
	dataHost.loadCATdata(fileName=filename, settingsName=settingsname)
	dataHost.CATbackgroundData(bkfilename)
	
	dataHost.setAllCAT(0.002)
	resultDict = dataHost.getResults(run_path, store=True)
 
	if plot:
		dataHost.storeFits(run_path, combined=True, separate=True)
  
	return resultDict, dataHost.settings
		
def get_timestamp(run_path):
	timestamp = datetime.strptime(os.path.split(run_path)[-1].split('_')[0], dateformat)
	return timestamp

def extract_fit(run_path, plot=True, cache_failed=True, cache_all=True):
	"""Gather relevant data from each measurement run

	Args:
		run_path : absolute path to the run directory
		plot (bool, optional): plot fits. Defaults to True.
		cache_failed (bool, optional): Cache failed fits. If false, refit. Doesn't refit non-failed fits. Defaults to True.
		cache_all (bool, optional): If false, ignore any cached fit_results. Defaults to True.

	Returns:
		a 3-tuple (fit_results, settings, timestamp)
	"""
	fit_results, settings, timestamp = {}, {}, None
	
	if not os.path.isdir(run_path):
		return fit_results, settings, timestamp  # directory is not a run directory

	try:
		timestamp = get_timestamp(run_path)
  
  	# TODO: specify which error to catch
	except Exception as e:
		print("Error extracting timestamp from: ", run_path)
		print(traceback.format_exc())
	
	MAT_fit_cache_path = os.path.join(run_path, 'resultDict.txt')
 
	if not os.path.exists(MAT_fit_cache_path) or not cache_all:
		
		try: 
			fit_results, settings = save_fit_results(run_path, plot=plot)
		except Exception as e:
			print(traceback.format_exc())
			print("Fitting ERROR at ", os.path.basename(run_path), '\n')

			with open(MAT_fit_cache_path, 'w') as f:
				f.write(str('MAT fit failed'))
		
	else:
		print("Accessing cached results from :", os.path.basename(run_path))
  
		fit_results = open(MAT_fit_cache_path, 'r').read()

		if fit_results == 'MAT fit failed':
			if not cache_failed:
				# fit regardless of cached result
				try: 
					fit_results, settings = save_fit_results(run_path, plot=plot)
				except Exception as e:
					print(traceback.format_exc())
					print("Fitting ERROR at ", os.path.basename(run_path), '\n')
	
					with open(MAT_fit_cache_path, 'w') as f:
						f.write(str('MAT fit failed'))	
			else:
				print("Failed fit at :", os.path.basename(run_path))
				fit_results = {}

		else:
			fit_results = eval(open(MAT_fit_cache_path, 'r').read())
   
			settingsname = os.path.join(run_path, 'Settings.txt')
			settings = eval(open(settingsname, 'r').read())
   
	return fit_results, settings, timestamp



def get_row(run_path, **kwargs):
			
   fit_results, settings, timestamp = extract_fit(run_path, **kwargs)
   row = {**fit_results, **settings, **{'timestamp':timestamp}}
   
   return row

   
def get_data_frame(data_dir, parallel=True, in_process_run=False, **kwargs):
   
	run_path_arr = []
	rows = []
	
	for relative_path in os.listdir(data_dir):
		run_path_arr.append(os.path.join(data_dir, relative_path))
  
	if in_process_run:
		run_path_arr.pop()

	run_path_arr = sorted(run_path_arr)
	
	if parallel:
		with Pool(4) as p:
			rows = list(tqdm(p.imap(partial(get_row, **kwargs), run_path_arr), total=len(run_path_arr)))
	
	else:
		for run_path in tqdm(run_path_arr):
		   rows.append(get_row(run_path, **kwargs))

	return pd.DataFrame.from_dict(rows)

def add_wavemeter_data(df, wmeter_csv_path, window_size=100, num_rows=50):


	"""Extract unique frequnecy values from wavemeter data
	Returns:
		unique_levels (list): unique frequency values in wavemeter data
	"""
 
	# TODO: modify dataframe in place with frequency data
 
	wdata = pd.read_csv(wmeter_csv_path, skiprows=2)
	wdata.dropna(inplace=True)
	freq_data = np.array(wdata.iloc[:, 0])
	try:
		freq_data = np.array([float(item) for item in freq_data if item.replace('.','').isdigit()])
	except Exception as e:
		print(e)
 
	max_freq = freq_data.max()
	min_freq = freq_data.min()

	return freq_data, max_freq, min_freq

def plot_results(ax, dfs, max_freq, min_freq=0.0, mfc='red', fmt='o', ms=5, save_folder=False, xscale=1.0, yscale=1.0, **kwargs):
	FREQVSVOLT = 221.0 
	FREQVSCURR = 1.13
	
	if not type(dfs) == list:
		freqs = ((max_freq-PUMP_FREQUENCY)-(dfs.dropna()['tempV']-dfs.dropna()['tempV'].min())*FREQVSVOLT- (dfs.dropna()['currV']-dfs.dropna()['currV'].min())*FREQVSCURR)*xscale
		dfs=[dfs]
  
	plt.gcf().set_dpi(300)
	
	for df in dfs:
		df = df.dropna()
		ax.errorbar(freqs, 
			   df['ratio']*yscale,
			   yerr=df['ratioErr'],
			   fmt=fmt, mfc=mfc, color='black', ms=ms, **kwargs)
		ax.set_ylabel(r'$\mathbf{\frac{V_{ss, cat}}{V_{ss}}} $ ', **labeldict)
		ax.set_xlabel(r'$\Delta $ (GHz)', **labeldict)
	
	if save_folder:
		plt.savefig(os.path.join(save_folder, 'ratio_vs_freq.png'))
	
	return freqs, ax
  
	#return plt.gca(), plt.gcf()
	#plt.show()

def plot_spline_fit(ax, x, y, s=1, yerr=None, color='black', scolor='black',figsize=(12,5), save_folder=None, title='',alpha=0.5,dpi=200, label='plot',**kwargs):
	from scipy.interpolate import splev, splrep
	xnew = np.linspace(min(x), max(x), 3*len(x) )

	y = [b for a,b in sorted(zip(x,y), key=lambda pair: pair[0])]
	if yerr is not None:
		yerr = [b for a,b in sorted(zip(x,yerr), key=lambda pair: pair[0])]
 
	x = sorted(x)

	spl = splrep(x, y, s=s)
	ynew = splev(xnew, spl)

	
	plt.gcf().set_dpi(dpi)
	plt.gcf().set_size_inches(figsize)
	
	if yerr is not None:
		ax.errorbar(x, y, yerr=yerr, fmt='o', **kwargs)
	else:
		ax.plot(x,y, 'o', **kwargs)
	ax.plot(xnew, ynew, '-', color=scolor, alpha=alpha, label=label, **kwargs)
 
	ax.set_ylabel(r'$\mathbf{\frac{V_{ss, cat}}{V_{ss}}} $ ', **labeldict)
	ax.set_xlabel(r'$\Delta $ (GHz)', **labeldict)
 
	ax.set_title(title, **titledict)
	if save_folder:
		plt.savefig(os.path.join(save_folder, 'spline_ratio_vs_freq.png'))
	
	return ax
 
def plot_polyfit(x_data, y_data, spline_degree):
	
	coefficients = np.polyfit(x_data, y_data, spline_degree)

	x_interp = np.linspace(min(x_data), max(x_data), 100)
	y_interp = np.polyval(coefficients, x_interp)

	plt.scatter(x_data, y_data, label='Original Data')
	plt.plot(x_interp, y_interp, label='Polynomial Interpolation (Degree={})'.format(spline_degree))

def collect_plots(source, destination, plot_name):
	print(f'Collecting plots from {os.path.basename(source)}')
	import shutil

	os.makedirs(destination, exist_ok=True)

	plot_files = []
	for root, dirs, files in os.walk(source):
		
		for file in files:
			if file == plot_name:
				plot_files.append(os.path.join(root, file))

	for i, plot_file in enumerate(plot_files, start=0):
		new_filename = f'{i}{plot_name}'
		destination_path = os.path.join(destination, new_filename)
		shutil.copy(plot_file, destination_path)

def create_GIF(images_folder, image_name):
	import imageio
	with imageio.get_writer(os.path.join(images_folder, f'{image_name}movie.gif'), mode='I', duration=0.5) as writer:
		for filename in os.listdir(images_folder):
			if image_name in filename:
				image = imageio.imread(os.path.join(images_folder, filename))
				writer.append_data(image)

def staircase_fit(data, peak_height=0.1, distance=100, data_offset=1, window_size=1, inc_final_peak=True):
	def moving_average(arr, window_size):
		weights = np.ones(window_size) / window_size
		return np.convolve(arr, weights, mode='valid')

	convdata1 = moving_average(data, window_size)
	convdata2 = moving_average(data[data_offset+1:], window_size )
	final = convdata1[:len(convdata2)]-convdata2
	# plt.plot(data)
	# plt.plot(convdata1)
	# plt.plot(convdata2)
	# plt.show()
	# plt.plot(final)

	
	from scipy.signal import find_peaks
	x= final
	peaks, _ = find_peaks(x, height=peak_height, distance=distance)
	peaks = np.insert(peaks, 0, 0)
	levels = []
	plot_arr = []
	for i, peak in enumerate(peaks):
		
		if i < len(peaks) - 1:
			temp = data[ peaks[i]:peaks[i+1] ]
			plot_arr.extend( np.ones_like(temp)*np.mean(temp))
			levels.append(np.mean(temp))
	if inc_final_peak:
		temp = data[peaks[-1]:]
		levels.append(np.mean(temp))
		plot_arr.extend( np.ones_like(temp)*np.mean(temp))
  
	plt.plot(x)
	plt.plot(peaks, x[peaks], "x")
	plt.plot(np.zeros_like(x), "--", color="gray")
	plt.show()
	
	plt.plot(data)
	plt.plot(np.ravel((plot_arr)))
	plt.show()
	plt.close()
	plt.plot(np.array(levels)[np.where(abs(np.diff(levels))>0.05)[0]], 'o', ms=5)
 
	return levels

def load_single_run(run_path):
	filename = os.path.join(run_path, 'data.csv')
	bkfilename = os.path.join(run_path, 'data_oldPD.csv')
	settingsname = os.path.join(run_path, 'Settings.txt')
	
	dh1 = MTdataHost(SAMPLE_RATE)
	dh1.loadCATdata(fileName=filename, settingsName=settingsname)
	
	return dh1
	# *-----------------------
	# *RELATIVE SCATTERING RATE
	# *-----------------------


def get_rel_scattering_df(data_folder):
	depth_ratios_df = []
	listdir = sorted(os.listdir(data_folder))
	try:
		for run_folder1, run_folder2 in [listdir[i:i+2] for i in range(len(listdir))[::2]]:
			try:
				run_path1 = os.path.join(data_folder, run_folder1)
				run_path2 = os.path.join(data_folder, run_folder2)
				result = {}
				with open(os.path.join(run_path1, 'twoSettings.txt'), 'r') as f:
					settings = f.read() 
					import re

					pattern = r'(\w+)\s*=\s*\(([\d.]+),\s*([\d.]+)\)'

					matches = re.findall(pattern, settings)

					
					for match in matches:
						key = match[0]
						value1 = float(match[1])
						value2 = float(match[2])
						result[key] = (value1, value2)

					print(result)
				with open(os.path.join(run_path2, 'twoSettings.txt'), 'r') as f:
					pass
					#print(f.readlines())
				
				timestamp = get_timestamp(run_path)
				fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
				
				extracted_values = {
						'pa1': result['pd1'][0],
						'pd1': result['pd1'][1],
						'pa2': result['pd2'][0],
						'pd2': result['pd2'][1],
						'depth_ratio': 1/float(depth_ratio), # ratio between current and std settings
      					'timestamp': timestamp
					}
				depth_ratios_df.append(extracted_values)
				
				print('\n')
			except Exception as e:
					print(traceback.format_exc())
					print(f'Error {e} at {run_folder1, run_folder2}')
	except Exception as e:
		print(f'Error {e}')

	depth_ratios_df = pd.DataFrame(depth_ratios_df)
 
	return depth_ratios_df

def get_rel_scattering(run_path1, run_path2):
	resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
	resultDict2, scat_ratio2 = _load_single_run_rel_scat(run_path2, plot=True)
	
	print(f"scat_ratio 1, (2 inverted) = {scat_ratio1:.3f}, {1/scat_ratio2:.3f}")
	scat_ratio_avg = (scat_ratio1+1/scat_ratio2)/2
	
	Rratio = resultDict1['initMOTR']/resultDict2['initMOTR']
	print(fr"Rratio = {resultDict1['initMOTR']:.3f} / {resultDict2['initMOTR']:.3f} = {Rratio:.3f}")
	depthRatio = np.sqrt(Rratio/scat_ratio_avg)
	
	return resultDict1, resultDict2, depthRatio


def _load_single_run_rel_scat(run_path, plot=False, cache_all=True):
	filename = os.path.join(run_path, 'data.csv')
	settingsname = os.path.join(run_path, 'Settings.txt')
	
	MAT_fit_cache_path = os.path.join(run_path, 'resultDict.txt')
	fit_results = {}
	if not os.path.exists(MAT_fit_cache_path) or not cache_all:
		
		try: 
			dh1 = MTdataHost(SAMPLE_RATE)
			dh1.loadCATdata(fileName=filename, settingsName=settingsname)

			dh1.tBaseline = 1
			dh1.tLoad = 2
			dh1.timeLoad = 30
			dh1.tReload = dh1.tLoad + dh1.timeLoad
			dh1.timeReload = 1
			dh1.tCATbackground = dh1.tReload + dh1.timeReload

			dh1.setOffset()
			dh1.setCATtiming()
			dh1.setAllCAT(0.002)

			fit_results = dh1.getResults(run_path, store=True)
			if plot:
				dh1.storeFits(run_path, combined=True, separate=False)
		except Exception as e:
			print(traceback.format_exc())
			print("Fitting ERROR at ", os.path.basename(run_path), '\n')

			with open(MAT_fit_cache_path, 'w') as f:
				f.write(str('MAT fit failed'))
		
	else:
		print("Accessing cached results from :", os.path.basename(run_path))

		fit_results = open(MAT_fit_cache_path, 'r').read()

		if fit_results == 'MAT fit failed':
			print("Failed fit at :", os.path.basename(run_path))
			fit_results = {}

		else:
			fit_results = eval(open(MAT_fit_cache_path, 'r').read())


	
	scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
	fit_results['scat_ratio'] = scat_ratio
 	#scat_ratio = dh1.motSS/(dh1.reloadVolt+dh1.baseVolt - (dh1.CATbackgroundVolt+dh1.noLightBackground))
	
	return fit_results, scat_ratio

def scat_rate(I, delta, gamma=6.065, Is=1.669):
	"""_summary_

	Args:
		I (float): intensity (Mhz)
		delta (float): detuning (Mhz)
		gamma (float, optional): linewidth (Mhz) Defaults to 6.065.
		Is (float, optional): Should be one of 3.576(isotropic), 2.503(pi), 1.669 (sigma+-). Defaults to 1.669.

	Returns:
		_type_: gamma: the scattering rate
	"""
	return gamma*I/(2*Is*(1+I/Is+4*(delta/gamma)**2))

if __name__ == '__main__':
	run_path = r"C:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\CATMeasurements\testPArun9\16-53-10"
	filename = os.path.join(run_path, 'data.csv')
	bkfilename = os.path.join(run_path, 'data_oldPD.csv')
	settingsname = os.path.join(run_path, 'Settings.txt')
	
	dh1 = MTdataHost(SAMPLE_RATE)
	dh1.loadCATdata(fileName=filename, settingsName=settingsname)
	
 	#dh1.CATbackgroundData(bkfilename)
	dh1.setAllCAT(0.002)
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
In [ ]:
get_rel_scattering_df(r'C:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\CATMeasurements\relScatRate\TrapDepthMap')
{'pd1': (1.85, 84.0), 'pd2': (1.125, 82.4)}
Accessing cached results from : 17-56-41
Failed fit at : 17-56-41
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('17-56-41', '17-57-25')
{'pd1': (1.85, 84.0), 'pd2': (1.125, 80.8)}
Accessing cached results from : 17-58-10
Failed fit at : 17-58-10
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('17-58-10', '17-58-54')
{'pd1': (1.85, 84.0), 'pd2': (1.125, 86.4)}
Accessing cached results from : 17-59-38
Failed fit at : 17-59-38
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('17-59-38', '18-00-22')
{'pd1': (1.85, 84.0), 'pd2': (1.125, 85.6)}
Accessing cached results from : 18-01-06
Failed fit at : 18-01-06
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('18-01-06', '18-01-50')
{'pd1': (1.85, 84.0), 'pd2': (1.125, 80.0)}
Accessing cached results from : 18-02-39
Failed fit at : 18-02-39
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('18-02-39', '18-03-31')
{'pd1': (1.85, 84.0), 'pd2': (1.125, 84.0)}
Accessing cached results from : 18-04-24
Failed fit at : 18-04-24
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('18-04-24', '18-05-17')
{'pd1': (1.85, 84.0), 'pd2': (1.125, 81.6)}
Accessing cached results from : 18-06-11
Failed fit at : 18-06-11
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('18-06-11', '18-07-04')
{'pd1': (1.85, 84.0), 'pd2': (1.125, 83.2)}
Accessing cached results from : 18-07-59
Failed fit at : 18-07-59
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('18-07-59', '18-08-51')
{'pd1': (1.85, 84.0), 'pd2': (1.125, 88.0)}
Accessing cached results from : 18-09-42
Failed fit at : 18-09-42
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('18-09-42', '18-10-35')
{'pd1': (1.85, 84.0), 'pd2': (1.125, 87.2)}
Accessing cached results from : 18-11-29
Failed fit at : 18-11-29
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('18-11-29', '18-12-22')
{'pd1': (1.85, 84.0), 'pd2': (1.125, 84.8)}
Accessing cached results from : 18-13-17
Failed fit at : 18-13-17
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('18-13-17', '18-14-10')
{'pd1': (1.85, 84.0), 'pd2': (0.6900000000000001, 82.4)}
Accessing cached results from : 18-15-02
Failed fit at : 18-15-02
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('18-15-02', '18-15-55')
{'pd1': (1.85, 84.0), 'pd2': (0.6900000000000001, 80.8)}
Accessing cached results from : 18-16-49
Failed fit at : 18-16-49
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('18-16-49', '18-17-41')
{'pd1': (1.85, 84.0), 'pd2': (0.6900000000000001, 86.4)}
Accessing cached results from : 18-18-33
Failed fit at : 18-18-33
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('18-18-33', '18-19-25')
{'pd1': (1.85, 84.0), 'pd2': (0.6900000000000001, 85.6)}
Accessing cached results from : 18-20-18
Failed fit at : 18-20-18
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('18-20-18', '18-21-10')
{'pd1': (1.85, 84.0), 'pd2': (0.6900000000000001, 80.0)}
Accessing cached results from : 18-22-04
Failed fit at : 18-22-04
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('18-22-04', '18-22-56')
{'pd1': (1.85, 84.0), 'pd2': (0.6900000000000001, 84.0)}
Accessing cached results from : 18-23-50
Failed fit at : 18-23-50
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('18-23-50', '18-24-46')
{'pd1': (1.85, 84.0), 'pd2': (0.6900000000000001, 81.6)}
Accessing cached results from : 18-25-41
Failed fit at : 18-25-41
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('18-25-41', '18-26-35')
{'pd1': (1.85, 84.0), 'pd2': (0.6900000000000001, 83.2)}
Accessing cached results from : 18-27-30
Failed fit at : 18-27-30
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('18-27-30', '18-28-23')
{'pd1': (1.85, 84.0), 'pd2': (0.6900000000000001, 88.0)}
Accessing cached results from : 18-29-14
Failed fit at : 18-29-14
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('18-29-14', '18-30-07')
{'pd1': (1.85, 84.0), 'pd2': (0.6900000000000001, 87.2)}
Accessing cached results from : 18-30-58
Failed fit at : 18-30-58
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('18-30-58', '18-31-50')
{'pd1': (1.85, 84.0), 'pd2': (0.6900000000000001, 84.8)}
Accessing cached results from : 18-32-43
Failed fit at : 18-32-43
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('18-32-43', '18-33-33')
{'pd1': (1.85, 84.0), 'pd2': (1.705, 82.4)}
Accessing cached results from : 18-34-17
Failed fit at : 18-34-17
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('18-34-17', '18-35-01')
{'pd1': (1.85, 84.0), 'pd2': (1.705, 80.8)}
Accessing cached results from : 18-35-45
Failed fit at : 18-35-45
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('18-35-45', '18-36-37')
{'pd1': (1.85, 84.0), 'pd2': (1.705, 86.4)}
Accessing cached results from : 18-37-28
Failed fit at : 18-37-28
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('18-37-28', '18-38-22')
{'pd1': (1.85, 84.0), 'pd2': (1.705, 85.6)}
Accessing cached results from : 18-39-14
Failed fit at : 18-39-14
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('18-39-14', '18-40-07')
{'pd1': (1.85, 84.0), 'pd2': (1.705, 80.0)}
Accessing cached results from : 18-41-02
Failed fit at : 18-41-02
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('18-41-02', '18-41-55')
{'pd1': (1.85, 84.0), 'pd2': (1.705, 84.0)}
Accessing cached results from : 18-42-50
Failed fit at : 18-42-50
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('18-42-50', '18-43-45')
{'pd1': (1.85, 84.0), 'pd2': (1.705, 81.6)}
Accessing cached results from : 18-44-38
Failed fit at : 18-44-38
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('18-44-38', '18-45-32')
{'pd1': (1.85, 84.0), 'pd2': (1.705, 83.2)}
Accessing cached results from : 18-46-25
Failed fit at : 18-46-25
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('18-46-25', '18-47-18')
{'pd1': (1.85, 84.0), 'pd2': (1.705, 88.0)}
Accessing cached results from : 18-48-12
Failed fit at : 18-48-12
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('18-48-12', '18-49-06')
{'pd1': (1.85, 84.0), 'pd2': (1.705, 87.2)}
Accessing cached results from : 18-50-01
Failed fit at : 18-50-01
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('18-50-01', '18-50-54')
{'pd1': (1.85, 84.0), 'pd2': (1.705, 84.8)}
Accessing cached results from : 18-51-46
Failed fit at : 18-51-46
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('18-51-46', '18-52-38')
{'pd1': (1.85, 84.0), 'pd2': (0.4, 82.4)}
Accessing cached results from : 18-53-31
Failed fit at : 18-53-31
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('18-53-31', '18-54-26')
{'pd1': (1.85, 84.0), 'pd2': (0.4, 80.8)}
Accessing cached results from : 18-55-20
Failed fit at : 18-55-20
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('18-55-20', '18-56-14')
{'pd1': (1.85, 84.0), 'pd2': (0.4, 86.4)}
Accessing cached results from : 18-57-09
Failed fit at : 18-57-09
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('18-57-09', '18-58-04')
{'pd1': (1.85, 84.0), 'pd2': (0.4, 85.6)}
Accessing cached results from : 18-58-58
Failed fit at : 18-58-58
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('18-58-58', '18-59-53')
{'pd1': (1.85, 84.0), 'pd2': (0.4, 80.0)}
Accessing cached results from : 19-00-50
Failed fit at : 19-00-50
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('19-00-50', '19-01-45')
{'pd1': (1.85, 84.0), 'pd2': (0.4, 84.0)}
Accessing cached results from : 19-02-37
Failed fit at : 19-02-37
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('19-02-37', '19-03-30')
{'pd1': (1.85, 84.0), 'pd2': (0.4, 81.6)}
Accessing cached results from : 19-04-25
Failed fit at : 19-04-25
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('19-04-25', '19-05-18')
{'pd1': (1.85, 84.0), 'pd2': (0.4, 83.2)}
Accessing cached results from : 19-06-09
Failed fit at : 19-06-09
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('19-06-09', '19-07-03')
{'pd1': (1.85, 84.0), 'pd2': (0.4, 88.0)}
Accessing cached results from : 19-07-58
Failed fit at : 19-07-58
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('19-07-58', '19-08-50')
{'pd1': (1.85, 84.0), 'pd2': (0.4, 87.2)}
Accessing cached results from : 19-09-45
Failed fit at : 19-09-45
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('19-09-45', '19-10-40')
{'pd1': (1.85, 84.0), 'pd2': (0.4, 84.8)}
Accessing cached results from : 19-11-33
Failed fit at : 19-11-33
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('19-11-33', '19-12-26')
{'pd1': (1.85, 84.0), 'pd2': (0.9800000000000001, 82.4)}
Accessing cached results from : 19-13-21
Failed fit at : 19-13-21
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('19-13-21', '19-14-14')
{'pd1': (1.85, 84.0), 'pd2': (0.9800000000000001, 80.8)}
Accessing cached results from : 19-15-07
Failed fit at : 19-15-07
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('19-15-07', '19-15-58')
{'pd1': (1.85, 84.0), 'pd2': (0.9800000000000001, 86.4)}
Accessing cached results from : 19-16-53
Failed fit at : 19-16-53
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('19-16-53', '19-17-45')
{'pd1': (1.85, 84.0), 'pd2': (0.9800000000000001, 85.6)}
Accessing cached results from : 19-18-39
Failed fit at : 19-18-39
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('19-18-39', '19-19-32')
{'pd1': (1.85, 84.0), 'pd2': (0.9800000000000001, 80.0)}
Accessing cached results from : 19-20-25
Failed fit at : 19-20-25
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('19-20-25', '19-21-18')
{'pd1': (1.85, 84.0), 'pd2': (0.9800000000000001, 84.0)}
Accessing cached results from : 19-22-11
Failed fit at : 19-22-11
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('19-22-11', '19-23-06')
{'pd1': (1.85, 84.0), 'pd2': (0.9800000000000001, 81.6)}
Accessing cached results from : 19-23-58
Failed fit at : 19-23-58
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('19-23-58', '19-24-50')
{'pd1': (1.85, 84.0), 'pd2': (0.9800000000000001, 83.2)}
Accessing cached results from : 19-25-42
Failed fit at : 19-25-42
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('19-25-42', '19-26-32')
{'pd1': (1.85, 84.0), 'pd2': (0.9800000000000001, 88.0)}
Accessing cached results from : 19-27-24
Failed fit at : 19-27-24
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('19-27-24', '19-28-17')
{'pd1': (1.85, 84.0), 'pd2': (0.9800000000000001, 87.2)}
Accessing cached results from : 19-29-10
Failed fit at : 19-29-10
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('19-29-10', '19-30-04')
{'pd1': (1.85, 84.0), 'pd2': (0.9800000000000001, 84.8)}
Accessing cached results from : 19-30-56
Failed fit at : 19-30-56
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('19-30-56', '19-31-49')
{'pd1': (1.85, 84.0), 'pd2': (0.8350000000000001, 82.4)}
Accessing cached results from : 19-32-43
Failed fit at : 19-32-43
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('19-32-43', '19-33-39')
{'pd1': (1.85, 84.0), 'pd2': (0.8350000000000001, 80.8)}
Accessing cached results from : 19-34-31
Failed fit at : 19-34-31
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('19-34-31', '19-35-25')
{'pd1': (1.85, 84.0), 'pd2': (0.8350000000000001, 86.4)}
Accessing cached results from : 19-36-19
Failed fit at : 19-36-19
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('19-36-19', '19-37-13')
{'pd1': (1.85, 84.0), 'pd2': (0.8350000000000001, 85.6)}
Accessing cached results from : 19-38-05
Failed fit at : 19-38-05
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('19-38-05', '19-38-59')
{'pd1': (1.85, 84.0), 'pd2': (0.8350000000000001, 80.0)}
Accessing cached results from : 19-39-54
Failed fit at : 19-39-54
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('19-39-54', '19-40-47')
{'pd1': (1.85, 84.0), 'pd2': (0.8350000000000001, 84.0)}
Accessing cached results from : 19-41-43
Failed fit at : 19-41-43
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('19-41-43', '19-42-38')
{'pd1': (1.85, 84.0), 'pd2': (0.8350000000000001, 81.6)}
Accessing cached results from : 19-43-34
Failed fit at : 19-43-34
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('19-43-34', '19-44-27')
{'pd1': (1.85, 84.0), 'pd2': (0.8350000000000001, 83.2)}
Accessing cached results from : 19-45-18
Failed fit at : 19-45-18
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('19-45-18', '19-46-12')
{'pd1': (1.85, 84.0), 'pd2': (0.8350000000000001, 88.0)}
Accessing cached results from : 19-47-08
Failed fit at : 19-47-08
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('19-47-08', '19-48-02')
{'pd1': (1.85, 84.0), 'pd2': (0.8350000000000001, 87.2)}
Accessing cached results from : 19-48-55
Failed fit at : 19-48-55
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('19-48-55', '19-49-51')
{'pd1': (1.85, 84.0), 'pd2': (0.8350000000000001, 84.8)}
Accessing cached results from : 19-50-43
Failed fit at : 19-50-43
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('19-50-43', '19-51-37')
{'pd1': (1.85, 84.0), 'pd2': (1.415, 82.4)}
Accessing cached results from : 19-52-32
Failed fit at : 19-52-32
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('19-52-32', '19-53-26')
{'pd1': (1.85, 84.0), 'pd2': (1.415, 80.8)}
Accessing cached results from : 19-54-20
Failed fit at : 19-54-20
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('19-54-20', '19-55-13')
{'pd1': (1.85, 84.0), 'pd2': (1.415, 86.4)}
Accessing cached results from : 19-56-07
Failed fit at : 19-56-07
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('19-56-07', '19-57-02')
{'pd1': (1.85, 84.0), 'pd2': (1.415, 85.6)}
Accessing cached results from : 19-57-56
Failed fit at : 19-57-56
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('19-57-56', '19-58-49')
{'pd1': (1.85, 84.0), 'pd2': (1.415, 80.0)}
Accessing cached results from : 19-59-43
Failed fit at : 19-59-43
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('19-59-43', '20-00-35')
{'pd1': (1.85, 84.0), 'pd2': (1.415, 84.0)}
Accessing cached results from : 20-01-27
Failed fit at : 20-01-27
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-01-27', '20-02-23')
{'pd1': (1.85, 84.0), 'pd2': (1.415, 81.6)}
Accessing cached results from : 20-03-16
Failed fit at : 20-03-16
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-03-16', '20-04-08')
{'pd1': (1.85, 84.0), 'pd2': (1.415, 83.2)}
Accessing cached results from : 20-05-01
Failed fit at : 20-05-01
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-05-01', '20-05-44')
{'pd1': (1.85, 84.0), 'pd2': (1.415, 88.0)}
Accessing cached results from : 20-06-28
Failed fit at : 20-06-28
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-06-28', '20-07-12')
{'pd1': (1.85, 84.0), 'pd2': (1.415, 87.2)}
Accessing cached results from : 20-07-55
Failed fit at : 20-07-55
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-07-55', '20-08-39')
{'pd1': (1.85, 84.0), 'pd2': (1.415, 84.8)}
Accessing cached results from : 20-09-22
Failed fit at : 20-09-22
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-09-22', '20-10-06')
{'pd1': (1.85, 84.0), 'pd2': (0.545, 82.4)}
Accessing cached results from : 20-10-49
Failed fit at : 20-10-49
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-10-49', '20-11-33')
{'pd1': (1.85, 84.0), 'pd2': (0.545, 80.8)}
Accessing cached results from : 20-12-17
Failed fit at : 20-12-17
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-12-17', '20-13-01')
{'pd1': (1.85, 84.0), 'pd2': (0.545, 86.4)}
Accessing cached results from : 20-13-44
Failed fit at : 20-13-44
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-13-44', '20-14-28')
{'pd1': (1.85, 84.0), 'pd2': (0.545, 85.6)}
Accessing cached results from : 20-15-12
Failed fit at : 20-15-12
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-15-12', '20-15-55')
{'pd1': (1.85, 84.0), 'pd2': (0.545, 80.0)}
Accessing cached results from : 20-16-39
Failed fit at : 20-16-39
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-16-39', '20-17-24')
{'pd1': (1.85, 84.0), 'pd2': (0.545, 84.0)}
Accessing cached results from : 20-18-07
Failed fit at : 20-18-07
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-18-07', '20-18-51')
{'pd1': (1.85, 84.0), 'pd2': (0.545, 81.6)}
Accessing cached results from : 20-19-35
Failed fit at : 20-19-35
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-19-35', '20-20-19')
{'pd1': (1.85, 84.0), 'pd2': (0.545, 83.2)}
Accessing cached results from : 20-21-02
Failed fit at : 20-21-02
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-21-02', '20-21-47')
{'pd1': (1.85, 84.0), 'pd2': (0.545, 88.0)}
Accessing cached results from : 20-22-32
Failed fit at : 20-22-32
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-22-32', '20-23-18')
{'pd1': (1.85, 84.0), 'pd2': (0.545, 87.2)}
Accessing cached results from : 20-24-04
Failed fit at : 20-24-04
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-24-04', '20-24-50')
{'pd1': (1.85, 84.0), 'pd2': (0.545, 84.8)}
Accessing cached results from : 20-25-34
Failed fit at : 20-25-34
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-25-34', '20-26-20')
{'pd1': (1.85, 84.0), 'pd2': (1.27, 82.4)}
Accessing cached results from : 20-27-05
Failed fit at : 20-27-05
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-27-05', '20-27-51')
{'pd1': (1.85, 84.0), 'pd2': (1.27, 80.8)}
Accessing cached results from : 20-28-39
Failed fit at : 20-28-39
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-28-39', '20-29-29')
{'pd1': (1.85, 84.0), 'pd2': (1.27, 86.4)}
Accessing cached results from : 20-30-22
Failed fit at : 20-30-22
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-30-22', '20-31-20')
{'pd1': (1.85, 84.0), 'pd2': (1.27, 85.6)}
Accessing cached results from : 20-32-12
Failed fit at : 20-32-12
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-32-12', '20-33-07')
{'pd1': (1.85, 84.0), 'pd2': (1.27, 80.0)}
Accessing cached results from : 20-33-57
Failed fit at : 20-33-57
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-33-57', '20-34-48')
{'pd1': (1.85, 84.0), 'pd2': (1.27, 84.0)}
Accessing cached results from : 20-35-41
Failed fit at : 20-35-41
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-35-41', '20-36-35')
{'pd1': (1.85, 84.0), 'pd2': (1.27, 81.6)}
Accessing cached results from : 20-37-26
Failed fit at : 20-37-26
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-37-26', '20-38-18')
{'pd1': (1.85, 84.0), 'pd2': (1.27, 83.2)}
Accessing cached results from : 20-39-08
Failed fit at : 20-39-08
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-39-08', '20-39-58')
{'pd1': (1.85, 84.0), 'pd2': (1.27, 88.0)}
Accessing cached results from : 20-40-50
Failed fit at : 20-40-50
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-40-50', '20-41-42')
{'pd1': (1.85, 84.0), 'pd2': (1.27, 87.2)}
Accessing cached results from : 20-42-28
Failed fit at : 20-42-28
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-42-28', '20-43-15')
{'pd1': (1.85, 84.0), 'pd2': (1.27, 84.8)}
Accessing cached results from : 20-44-02
Failed fit at : 20-44-02
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-44-02', '20-44-50')
{'pd1': (1.85, 84.0), 'pd2': (1.56, 82.4)}
Accessing cached results from : 20-45-40
Failed fit at : 20-45-40
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-45-40', '20-46-29')
{'pd1': (1.85, 84.0), 'pd2': (1.56, 80.8)}
Accessing cached results from : 20-47-19
Failed fit at : 20-47-19
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-47-19', '20-48-09')
{'pd1': (1.85, 84.0), 'pd2': (1.56, 86.4)}
Accessing cached results from : 20-49-00
Failed fit at : 20-49-00
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-49-00', '20-49-52')
{'pd1': (1.85, 84.0), 'pd2': (1.56, 85.6)}
Accessing cached results from : 20-50-43
Failed fit at : 20-50-43
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-50-43', '20-51-33')
{'pd1': (1.85, 84.0), 'pd2': (1.56, 80.0)}
Accessing cached results from : 20-52-23
Failed fit at : 20-52-23
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-52-23', '20-53-13')
{'pd1': (1.85, 84.0), 'pd2': (1.56, 84.0)}
Accessing cached results from : 20-54-03
Failed fit at : 20-54-03
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-54-03', '20-54-56')
{'pd1': (1.85, 84.0), 'pd2': (1.56, 81.6)}
Accessing cached results from : 20-55-47
Failed fit at : 20-55-47
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-55-47', '20-56-40')
{'pd1': (1.85, 84.0), 'pd2': (1.56, 83.2)}
Accessing cached results from : 20-57-31
Failed fit at : 20-57-31
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-57-31', '20-58-23')
{'pd1': (1.85, 84.0), 'pd2': (1.56, 88.0)}
Accessing cached results from : 20-59-12
Failed fit at : 20-59-12
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-59-12', '20-59-57')
{'pd1': (1.85, 84.0), 'pd2': (1.56, 87.2)}
Accessing cached results from : 21-00-42
Failed fit at : 21-00-42
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('21-00-42', '21-01-27')
{'pd1': (1.85, 84.0), 'pd2': (1.56, 84.8)}
Accessing cached results from : 21-02-12
Failed fit at : 21-02-12
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('21-02-12', '21-02-56')
{'pd1': (1.85, 84.0), 'pd2': (1.85, 82.4)}
Accessing cached results from : 21-03-41
Failed fit at : 21-03-41
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('21-03-41', '21-04-25')
{'pd1': (1.85, 84.0), 'pd2': (1.85, 80.8)}
Accessing cached results from : 21-05-09
Failed fit at : 21-05-09
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('21-05-09', '21-05-53')
{'pd1': (1.85, 84.0), 'pd2': (1.85, 86.4)}
Accessing cached results from : 21-06-37
Failed fit at : 21-06-37
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('21-06-37', '21-07-20')
{'pd1': (1.85, 84.0), 'pd2': (1.85, 85.6)}
Accessing cached results from : 21-08-04
Failed fit at : 21-08-04
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('21-08-04', '21-08-57')
{'pd1': (1.85, 84.0), 'pd2': (1.85, 80.0)}
Accessing cached results from : 21-09-50
Failed fit at : 21-09-50
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('21-09-50', '21-10-43')
{'pd1': (1.85, 84.0), 'pd2': (1.85, 84.0)}
Accessing cached results from : 21-11-36
Failed fit at : 21-11-36
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('21-11-36', '21-12-29')
{'pd1': (1.85, 84.0), 'pd2': (1.85, 81.6)}
Accessing cached results from : 21-13-13
Failed fit at : 21-13-13
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('21-13-13', '21-13-57')
{'pd1': (1.85, 84.0), 'pd2': (1.85, 83.2)}
Accessing cached results from : 21-14-41
Failed fit at : 21-14-41
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('21-14-41', '21-15-24')
{'pd1': (1.85, 84.0), 'pd2': (1.85, 88.0)}
Accessing cached results from : 21-16-08
Failed fit at : 21-16-08
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('21-16-08', '21-16-52')
{'pd1': (1.85, 84.0), 'pd2': (1.85, 87.2)}
Accessing cached results from : 21-17-36
Failed fit at : 21-17-36
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('21-17-36', '21-18-19')
{'pd1': (1.85, 84.0), 'pd2': (1.85, 84.8)}
Accessing cached results from : 21-19-03
Failed fit at : 21-19-03
Traceback (most recent call last):
  File "<ipython-input-40-bc9c002d9b2f>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-40-bc9c002d9b2f>", line 575, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('21-19-03', '21-19-47')
Out[ ]:
In [ ]:
import os
import sys
from functools import partial
sys.path.append(os.path.join(os.getcwd(), '..')) #adds directory below as valid path
from  datetime import datetime, timedelta
dateformat = "%H-%M-%S"
from collections import deque
import traceback
from multiprocessing import Pool
from tqdm import tqdm

import scipy.constants as spc
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd

plt.rcParams['axes.grid'] = True
plt.rcParams['grid.linestyle'] = '--'

from MT_class_PID_new import MTdataHost
from global_folder.myplotsty import *
from global_folder.my_helpers import *

PUMP_FREQUENCY = 384228.6
REPUMP_FREQUENCY = 384228.6 + 6.56
SAMPLE_RATE = 2000
FREQVSVOLT = 221.0 
FREQVSCURR = 1.13

# TODO: find a better place for this
EXP_FOLDER =r'C:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\CATMeasurements'
MEASURE_FOLDER = os.path.join(EXP_FOLDER, 'testPArun16')
WDATA_FOLDER =os.path.join(MEASURE_FOLDER, 'testPArun16.csv')

# TODO: maybe make a run analysis class out of this?
def dump():
	fig, ax = plt.subplots()
	plot_results(ax, df, max_freq= 384219., fmt='o', mfc='red', save_folder=MEASURE_FOLDER)
	plt.savefig(os.path.join(MEASURE_FOLDER, 'ratio_vs_freq.png'))

	
	collect_plots(MEASURE_FOLDER, os.path.join(MEASURE_FOLDER, 'collected_plots'), 'deloadPhase.png')
 
	#*-----------------------
	#* SINGLE RUN
 	#*----------------------- 
  
	MEASURE_FOLDER = os.path.join(EXP_FOLDER, 'testPArun9')
	df = get_data_frame(MEASURE_FOLDER)
	df.dropna(inplace=True)
	#freqs = plot_results(df, 384201., save_folder=MEASURE_FOLDER)
 
	data = df.dropna()
	freqs = ((384201-PUMP_FREQUENCY)-(data['tempV']-df['tempV'].min())*FREQVSVOLT- (data['currV']-df['currV'].min())*FREQVSCURR)
	fig, ax = plt.subplots()
	plot_spline_fit(ax=ax, x=freqs, y=data['ratio'], yerr=data['ratioErr'], 
				 s=0.1, save_folder=MEASURE_FOLDER, 
				 mfc='red', color='black', 
				 title='Trap Depth = 1.99 K')
 
	# *-----------------------
	# * MULTIPLE RUN COMPARISON
 	# *-----------------------
	folders = [os.path.join(EXP_FOLDER, path ) for path in ['testPARun11', 'testPARun12', 'testPARun13', 'testPARun14']]
	dfs = [get_data_frame(measure_folder, cache_all=True) for measure_folder in folders]

	colors = ['red', 'dodgerblue', 'green', 'grey']
	max_freqs = [384178.881, 384178.593,384179.068, 384184.731]
	#max_freqs=[384178.599, 384179.091, 384184.733]

	zipped_data = list(zip(dfs, max_freqs))
	fig, ax = plt.subplots()
	for i, (df, max_freq)  in enumerate(zipped_data[:3]):
		data = df.dropna()
		freqs = ((max_freq-PUMP_FREQUENCY)-(data['tempV']-data['tempV'].min())*FREQVSVOLT- (data['currV']-data['currV'].min())*FREQVSCURR)
		color = colors[i]
		ax=plot_spline_fit(ax, x=freqs, y=data['ratio'], scolor=color, mfc=color,color=color, s=0.02, ms=5)

	#*-----------------------
	#* PARSING WAVEMETER DATA
 	#*-----------------------

	MEASURE_FOLDER = os.path.join(EXP_FOLDER, 'testPArun14')
	WDATA_FOLDER =os.path.join(MEASURE_FOLDER, 'testPArun14.csv')
	freq_data, max_freq, min_freq = add_wavemeter_data('', WDATA_FOLDER)
	data = freq_data[:]
	levels = staircase_fit(data)

	data = get_data_frame(MEASURE_FOLDER)
	data.dropna(inplace=True)
	freqs = ((max_freq)-(data['tempV']-data['tempV'].min())*FREQVSVOLT- (data['currV']-data['currV'].min())*FREQVSCURR)
	plt.plot(freqs)
 
	#*-----------------------
	#* GETTING DEPTH_RATIO DATAFRAME
 	#*-----------------------
	MEASURE_FOLDER = r'C:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\CATMeasurements\relScatRate'
	depth_ratios_df = get_rel_scattering_df(MEASURE_FOLDER)
	df_slice = depth_ratios_df[(depth_ratios_df['pa1']==1.85) & (depth_ratios_df['pd1']==84) & (depth_ratios_df['pd2'] == 84)]
	x = df_slice['pa2']
	y = df_slice['depth_ratio']
	plt.plot(x,y, 'o')

	#*-----------------------
	#* MEGA_RUN
 	#*-----------------------	
	MEASURE_FOLDER = os.path.join(EXP_FOLDER, 'testPARunMega')
	df = get_data_frame(MEASURE_FOLDER)
	df.dropna(inplace=True)

	df_grouped = df.groupby(by='pump_reference')
	min_ratios = df_grouped['ratio'].min()

	groups = dict(list(df_grouped))
	dfs = [df for df in groups.values()]
 
	max_freqs = [384182.5]*15
	#max_freqs=[384178.599, 384179.091, 384184.733]
	zipped_data = list(zip(dfs, max_freqs))
	fig, ax = plt.subplots()
	for i, (df, max_freq)  in enumerate(zipped_data[:]):
		data = df.dropna()
		freqs = ((max_freq-PUMP_FREQUENCY)-(data['tempV']-data['tempV'].min())*FREQVSVOLT- (data['currV']-data['currV'].min())*FREQVSCURR)
		ax=plot_spline_fit(ax, x=freqs, y=data['ratio'], yerr=data['ratioErr'],scolor=f'C{i}', mfc=f'C{i}',color=f'C{i}', s=0.0, ms=5, figsize=(10, 10), label=f"Pump Amplituide = { df.iloc[10]['pump_reference'] :.2f}", linewidth=2.5)

	plt.legend()

	plt.savefig(os.path.join(MEASURE_FOLDER, 'lossFeatures.png'))
	#*-----------------------
	#* MULTIPLE MEGARUN
	#*-----------------------
 
	folders = [os.path.join(EXP_FOLDER, path ) for path in ['testPArunMega', 'testPArunMega2']]
	dfs_mega = [get_data_frame(measure_folder, cache_all=True).dropna() for measure_folder in folders]

	dfs_grouped = [df_mega.groupby(by='pump_reference') for df_mega in dfs_mega]
	min_ratios = [df_grouped['ratio'].min() for df_grouped in dfs_grouped]

	groupss = [dict(list(df_grouped)) for df_grouped in dfs_grouped]
	dfs = [ [df for df in groups.values()] for groups in groupss]
 
	for row in dfs:
		x = [df['pump_reference'].mean() for df in row]
		y = [(df['ratio'].max() - df['ratio'].min())/df['motSS'].std() for df in row]
		plt.plot( x, y ,'-o', label=fr"$\delta$ = {180 - 2*row[0]['pump_AOM_freq'].mean()} MHz")
		plt.xlabel('Pump Amplitude')
		plt.ylabel(r'SNR $ = \frac{V_{ss, off} - V_{ss, on}}{\sigma_{V,off}}$ ')
	plt.legend()

def freq_misc():
	WDATA_FOLDER = r'C:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\CATMeasurements\CATcurrTestrun3.csv'
	freq_data = add_wavemeter_data('', WDATA_FOLDER)
	levels = staircase_fit(freq_data[0], peak_height=0.2, distance=50, data_offset=1, window_size=1) 

	plt.close()
 
	x = np.linspace(0, 4.9, 25)
	y = levels
 
	plt.plot(levels, '-o')
	plt.title('Levels plot')
	
	m, b, fit_line = my_linear_fit(x, y)
def save_fit_results(run_path, plot=False):
	filename = os.path.join(run_path, 'data.csv')
	bkfilename = os.path.join(run_path, 'data_oldPD.csv')
	settingsname = os.path.join(run_path, 'Settings.txt')
	
	dataHost = MTdataHost(SAMPLE_RATE)
	dataHost.loadCATdata(fileName=filename, settingsName=settingsname)
	dataHost.CATbackgroundData(bkfilename)
	
	dataHost.setAllCAT(0.002)
	resultDict = dataHost.getResults(run_path, store=True)
 
	if plot:
		dataHost.storeFits(run_path, combined=True, separate=True)
  
	return resultDict, dataHost.settings
		
def get_timestamp(run_path):
	timestamp = datetime.strptime(os.path.split(run_path)[-1].split('_')[0], dateformat)
	return timestamp

def extract_fit(run_path, plot=True, cache_failed=True, cache_all=True):
	"""Gather relevant data from each measurement run

	Args:
		run_path : absolute path to the run directory
		plot (bool, optional): plot fits. Defaults to True.
		cache_failed (bool, optional): Cache failed fits. If false, refit. Doesn't refit non-failed fits. Defaults to True.
		cache_all (bool, optional): If false, ignore any cached fit_results. Defaults to True.

	Returns:
		a 3-tuple (fit_results, settings, timestamp)
	"""
	fit_results, settings, timestamp = {}, {}, None
	
	if not os.path.isdir(run_path):
		return fit_results, settings, timestamp  # directory is not a run directory

	try:
		timestamp = get_timestamp(run_path)
  
  	# TODO: specify which error to catch
	except Exception as e:
		print("Error extracting timestamp from: ", run_path)
		print(traceback.format_exc())
	
	MAT_fit_cache_path = os.path.join(run_path, 'resultDict.txt')
 
	if not os.path.exists(MAT_fit_cache_path) or not cache_all:
		
		try: 
			fit_results, settings = save_fit_results(run_path, plot=plot)
		except Exception as e:
			print(traceback.format_exc())
			print("Fitting ERROR at ", os.path.basename(run_path), '\n')

			with open(MAT_fit_cache_path, 'w') as f:
				f.write(str('MAT fit failed'))
		
	else:
		print("Accessing cached results from :", os.path.basename(run_path))
  
		fit_results = open(MAT_fit_cache_path, 'r').read()

		if fit_results == 'MAT fit failed':
			if not cache_failed:
				# fit regardless of cached result
				try: 
					fit_results, settings = save_fit_results(run_path, plot=plot)
				except Exception as e:
					print(traceback.format_exc())
					print("Fitting ERROR at ", os.path.basename(run_path), '\n')
	
					with open(MAT_fit_cache_path, 'w') as f:
						f.write(str('MAT fit failed'))	
			else:
				print("Failed fit at :", os.path.basename(run_path))
				fit_results = {}

		else:
			fit_results = eval(open(MAT_fit_cache_path, 'r').read())
   
			settingsname = os.path.join(run_path, 'Settings.txt')
			settings = eval(open(settingsname, 'r').read())
   
	return fit_results, settings, timestamp



def get_row(run_path, **kwargs):
			
   fit_results, settings, timestamp = extract_fit(run_path, **kwargs)
   row = {**fit_results, **settings, **{'timestamp':timestamp}}
   
   return row

   
def get_data_frame(data_dir, parallel=True, in_process_run=False, **kwargs):
   
	run_path_arr = []
	rows = []
	
	for relative_path in os.listdir(data_dir):
		run_path_arr.append(os.path.join(data_dir, relative_path))
  
	if in_process_run:
		run_path_arr.pop()

	run_path_arr = sorted(run_path_arr)
	
	if parallel:
		with Pool(4) as p:
			rows = list(tqdm(p.imap(partial(get_row, **kwargs), run_path_arr), total=len(run_path_arr)))
	
	else:
		for run_path in tqdm(run_path_arr):
		   rows.append(get_row(run_path, **kwargs))

	return pd.DataFrame.from_dict(rows)

def add_wavemeter_data(df, wmeter_csv_path, window_size=100, num_rows=50):


	"""Extract unique frequnecy values from wavemeter data
	Returns:
		unique_levels (list): unique frequency values in wavemeter data
	"""
 
	# TODO: modify dataframe in place with frequency data
 
	wdata = pd.read_csv(wmeter_csv_path, skiprows=2)
	wdata.dropna(inplace=True)
	freq_data = np.array(wdata.iloc[:, 0])
	try:
		freq_data = np.array([float(item) for item in freq_data if item.replace('.','').isdigit()])
	except Exception as e:
		print(e)
 
	max_freq = freq_data.max()
	min_freq = freq_data.min()

	return freq_data, max_freq, min_freq

def plot_results(ax, dfs, max_freq, min_freq=0.0, mfc='red', fmt='o', ms=5, save_folder=False, xscale=1.0, yscale=1.0, **kwargs):
	FREQVSVOLT = 221.0 
	FREQVSCURR = 1.13
	
	if not type(dfs) == list:
		freqs = ((max_freq-PUMP_FREQUENCY)-(dfs.dropna()['tempV']-dfs.dropna()['tempV'].min())*FREQVSVOLT- (dfs.dropna()['currV']-dfs.dropna()['currV'].min())*FREQVSCURR)*xscale
		dfs=[dfs]
  
	plt.gcf().set_dpi(300)
	
	for df in dfs:
		df = df.dropna()
		ax.errorbar(freqs, 
			   df['ratio']*yscale,
			   yerr=df['ratioErr'],
			   fmt=fmt, mfc=mfc, color='black', ms=ms, **kwargs)
		ax.set_ylabel(r'$\mathbf{\frac{V_{ss, cat}}{V_{ss}}} $ ', **labeldict)
		ax.set_xlabel(r'$\Delta $ (GHz)', **labeldict)
	
	if save_folder:
		plt.savefig(os.path.join(save_folder, 'ratio_vs_freq.png'))
	
	return freqs, ax
  
	#return plt.gca(), plt.gcf()
	#plt.show()

def plot_spline_fit(ax, x, y, s=1, yerr=None, color='black', scolor='black',figsize=(12,5), save_folder=None, title='',alpha=0.5,dpi=200, label='plot',**kwargs):
	from scipy.interpolate import splev, splrep
	xnew = np.linspace(min(x), max(x), 3*len(x) )

	y = [b for a,b in sorted(zip(x,y), key=lambda pair: pair[0])]
	if yerr is not None:
		yerr = [b for a,b in sorted(zip(x,yerr), key=lambda pair: pair[0])]
 
	x = sorted(x)

	spl = splrep(x, y, s=s)
	ynew = splev(xnew, spl)

	
	plt.gcf().set_dpi(dpi)
	plt.gcf().set_size_inches(figsize)
	
	if yerr is not None:
		ax.errorbar(x, y, yerr=yerr, fmt='o', **kwargs)
	else:
		ax.plot(x,y, 'o', **kwargs)
	ax.plot(xnew, ynew, '-', color=scolor, alpha=alpha, label=label, **kwargs)
 
	ax.set_ylabel(r'$\mathbf{\frac{V_{ss, cat}}{V_{ss}}} $ ', **labeldict)
	ax.set_xlabel(r'$\Delta $ (GHz)', **labeldict)
 
	ax.set_title(title, **titledict)
	if save_folder:
		plt.savefig(os.path.join(save_folder, 'spline_ratio_vs_freq.png'))
	
	return ax
 
def plot_polyfit(x_data, y_data, spline_degree):
	
	coefficients = np.polyfit(x_data, y_data, spline_degree)

	x_interp = np.linspace(min(x_data), max(x_data), 100)
	y_interp = np.polyval(coefficients, x_interp)

	plt.scatter(x_data, y_data, label='Original Data')
	plt.plot(x_interp, y_interp, label='Polynomial Interpolation (Degree={})'.format(spline_degree))

def collect_plots(source, destination, plot_name):
	print(f'Collecting plots from {os.path.basename(source)}')
	import shutil

	os.makedirs(destination, exist_ok=True)

	plot_files = []
	for root, dirs, files in os.walk(source):
		
		for file in files:
			if file == plot_name:
				plot_files.append(os.path.join(root, file))

	for i, plot_file in enumerate(plot_files, start=0):
		new_filename = f'{i}{plot_name}'
		destination_path = os.path.join(destination, new_filename)
		shutil.copy(plot_file, destination_path)

def create_GIF(images_folder, image_name):
	import imageio
	with imageio.get_writer(os.path.join(images_folder, f'{image_name}movie.gif'), mode='I', duration=0.5) as writer:
		for filename in os.listdir(images_folder):
			if image_name in filename:
				image = imageio.imread(os.path.join(images_folder, filename))
				writer.append_data(image)

def staircase_fit(data, peak_height=0.1, distance=100, data_offset=1, window_size=1, inc_final_peak=True):
	def moving_average(arr, window_size):
		weights = np.ones(window_size) / window_size
		return np.convolve(arr, weights, mode='valid')

	convdata1 = moving_average(data, window_size)
	convdata2 = moving_average(data[data_offset+1:], window_size )
	final = convdata1[:len(convdata2)]-convdata2
	# plt.plot(data)
	# plt.plot(convdata1)
	# plt.plot(convdata2)
	# plt.show()
	# plt.plot(final)

	
	from scipy.signal import find_peaks
	x= final
	peaks, _ = find_peaks(x, height=peak_height, distance=distance)
	peaks = np.insert(peaks, 0, 0)
	levels = []
	plot_arr = []
	for i, peak in enumerate(peaks):
		
		if i < len(peaks) - 1:
			temp = data[ peaks[i]:peaks[i+1] ]
			plot_arr.extend( np.ones_like(temp)*np.mean(temp))
			levels.append(np.mean(temp))
	if inc_final_peak:
		temp = data[peaks[-1]:]
		levels.append(np.mean(temp))
		plot_arr.extend( np.ones_like(temp)*np.mean(temp))
  
	plt.plot(x)
	plt.plot(peaks, x[peaks], "x")
	plt.plot(np.zeros_like(x), "--", color="gray")
	plt.show()
	
	plt.plot(data)
	plt.plot(np.ravel((plot_arr)))
	plt.show()
	plt.close()
	plt.plot(np.array(levels)[np.where(abs(np.diff(levels))>0.05)[0]], 'o', ms=5)
 
	return levels

def load_single_run(run_path):
	filename = os.path.join(run_path, 'data.csv')
	bkfilename = os.path.join(run_path, 'data_oldPD.csv')
	settingsname = os.path.join(run_path, 'Settings.txt')
	
	dh1 = MTdataHost(SAMPLE_RATE)
	dh1.loadCATdata(fileName=filename, settingsName=settingsname)
	
	return dh1
	# *-----------------------
	# *RELATIVE SCATTERING RATE
	# *-----------------------


def get_rel_scattering_df(data_folder):
	depth_ratios_df = []
	listdir = sorted(os.listdir(data_folder))
	try:
		for run_folder1, run_folder2 in [listdir[i:i+2] for i in range(len(listdir))[::2]]:
			try:
				run_path1 = os.path.join(data_folder, run_folder1)
				run_path2 = os.path.join(data_folder, run_folder2)
				result = {}
				with open(os.path.join(run_path1, 'twoSettings.txt'), 'r') as f:
					settings = f.read() 
					import re

					pattern = r'(\w+)\s*=\s*\(([\d.]+),\s*([\d.]+)\)'

					matches = re.findall(pattern, settings)

					
					for match in matches:
						key = match[0]
						value1 = float(match[1])
						value2 = float(match[2])
						result[key] = (value1, value2)

					print(result)
				with open(os.path.join(run_path2, 'twoSettings.txt'), 'r') as f:
					pass
					#print(f.readlines())
				
				timestamp = get_timestamp(run_path)
				fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
				
				extracted_values = {
						'pa1': result['pd1'][0],
						'pd1': result['pd1'][1],
						'pa2': result['pd2'][0],
						'pd2': result['pd2'][1],
						'depth_ratio': 1/float(depth_ratio), # ratio between current and std settings
      					'timestamp': timestamp
					}
				depth_ratios_df.append(extracted_values)
				
				print('\n')
			except Exception as e:
					print(traceback.format_exc())
					print(f'Error {e} at {run_folder1, run_folder2}')
	except Exception as e:
		print(f'Error {e}')

	depth_ratios_df = pd.DataFrame(depth_ratios_df)
 
	return depth_ratios_df

def get_rel_scattering(run_path1, run_path2):
	resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
	resultDict2, scat_ratio2 = _load_single_run_rel_scat(run_path2, plot=True)
	
	print(f"scat_ratio 1, (2 inverted) = {scat_ratio1:.3f}, {1/scat_ratio2:.3f}")
	scat_ratio_avg = (scat_ratio1+1/scat_ratio2)/2
	
	Rratio = resultDict1['initMOTR']/resultDict2['initMOTR']
	print(fr"Rratio = {resultDict1['initMOTR']:.3f} / {resultDict2['initMOTR']:.3f} = {Rratio:.3f}")
	depthRatio = np.sqrt(Rratio/scat_ratio_avg)
	
	return resultDict1, resultDict2, depthRatio


def _load_single_run_rel_scat(run_path, plot=False, cache_all=True):
	filename = os.path.join(run_path, 'data.csv')
	settingsname = os.path.join(run_path, 'Settings.txt')
	
	MAT_fit_cache_path = os.path.join(run_path, 'resultDict.txt')
	fit_results = {}
	if not os.path.exists(MAT_fit_cache_path) or not cache_all:
		
		try: 
			dh1 = MTdataHost(SAMPLE_RATE)
			dh1.loadCATdata(fileName=filename, settingsName=settingsname)

			dh1.tBaseline = 1
			dh1.tLoad = 2
			dh1.timeLoad = 30
			dh1.tReload = dh1.tLoad + dh1.timeLoad
			dh1.timeReload = 1
			dh1.tCATbackground = dh1.tReload + dh1.timeReload

			dh1.setOffset()
			dh1.setCATtiming()
			dh1.setAllCAT(0.002)

			print('FITTINGGGGGGGGGGGG')
			fit_results = dh1.getResults(run_path, store=True)
			if plot:
				dh1.storeFits(run_path, combined=True, separate=False)
		except Exception as e:
			print(traceback.format_exc())
			print("Fitting ERROR at ", os.path.basename(run_path), '\n')

			with open(MAT_fit_cache_path, 'w') as f:
				f.write(str('MAT fit failed'))
		
	else:
		print("Accessing cached results from :", os.path.basename(run_path))

		fit_results = open(MAT_fit_cache_path, 'r').read()

		if fit_results == 'MAT fit failed':
			print("Failed fit at :", os.path.basename(run_path))
			fit_results = {}

		else:
			fit_results = eval(open(MAT_fit_cache_path, 'r').read())


	
	scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
	fit_results['scat_ratio'] = scat_ratio
 	#scat_ratio = dh1.motSS/(dh1.reloadVolt+dh1.baseVolt - (dh1.CATbackgroundVolt+dh1.noLightBackground))
	
	return fit_results, scat_ratio

def scat_rate(I, delta, gamma=6.065, Is=1.669):
	"""_summary_

	Args:
		I (float): intensity (Mhz)
		delta (float): detuning (Mhz)
		gamma (float, optional): linewidth (Mhz) Defaults to 6.065.
		Is (float, optional): Should be one of 3.576(isotropic), 2.503(pi), 1.669 (sigma+-). Defaults to 1.669.

	Returns:
		_type_: gamma: the scattering rate
	"""
	return gamma*I/(2*Is*(1+I/Is+4*(delta/gamma)**2))

if __name__ == '__main__':
	run_path = r"C:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\CATMeasurements\testPArun9\16-53-10"
	filename = os.path.join(run_path, 'data.csv')
	bkfilename = os.path.join(run_path, 'data_oldPD.csv')
	settingsname = os.path.join(run_path, 'Settings.txt')
	
	dh1 = MTdataHost(SAMPLE_RATE)
	dh1.loadCATdata(fileName=filename, settingsName=settingsname)
	
 	#dh1.CATbackgroundData(bkfilename)
	dh1.setAllCAT(0.002)
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
In [ ]:
get_rel_scattering_df(r'C:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\CATMeasurements\relScatRate\TrapDepthMap')
{'pd1': (1.85, 84.0), 'pd2': (1.125, 82.4)}
Accessing cached results from : 17-56-41
Failed fit at : 17-56-41
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('17-56-41', '17-57-25')
{'pd1': (1.85, 84.0), 'pd2': (1.125, 80.8)}
Accessing cached results from : 17-58-10
Failed fit at : 17-58-10
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('17-58-10', '17-58-54')
{'pd1': (1.85, 84.0), 'pd2': (1.125, 86.4)}
Accessing cached results from : 17-59-38
Failed fit at : 17-59-38
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('17-59-38', '18-00-22')
{'pd1': (1.85, 84.0), 'pd2': (1.125, 85.6)}
Accessing cached results from : 18-01-06
Failed fit at : 18-01-06
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('18-01-06', '18-01-50')
{'pd1': (1.85, 84.0), 'pd2': (1.125, 80.0)}
Accessing cached results from : 18-02-39
Failed fit at : 18-02-39
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('18-02-39', '18-03-31')
{'pd1': (1.85, 84.0), 'pd2': (1.125, 84.0)}
Accessing cached results from : 18-04-24
Failed fit at : 18-04-24
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('18-04-24', '18-05-17')
{'pd1': (1.85, 84.0), 'pd2': (1.125, 81.6)}
Accessing cached results from : 18-06-11
Failed fit at : 18-06-11
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('18-06-11', '18-07-04')
{'pd1': (1.85, 84.0), 'pd2': (1.125, 83.2)}
Accessing cached results from : 18-07-59
Failed fit at : 18-07-59
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('18-07-59', '18-08-51')
{'pd1': (1.85, 84.0), 'pd2': (1.125, 88.0)}
Accessing cached results from : 18-09-42
Failed fit at : 18-09-42
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('18-09-42', '18-10-35')
{'pd1': (1.85, 84.0), 'pd2': (1.125, 87.2)}
Accessing cached results from : 18-11-29
Failed fit at : 18-11-29
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('18-11-29', '18-12-22')
{'pd1': (1.85, 84.0), 'pd2': (1.125, 84.8)}
Accessing cached results from : 18-13-17
Failed fit at : 18-13-17
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('18-13-17', '18-14-10')
{'pd1': (1.85, 84.0), 'pd2': (0.6900000000000001, 82.4)}
Accessing cached results from : 18-15-02
Failed fit at : 18-15-02
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('18-15-02', '18-15-55')
{'pd1': (1.85, 84.0), 'pd2': (0.6900000000000001, 80.8)}
Accessing cached results from : 18-16-49
Failed fit at : 18-16-49
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('18-16-49', '18-17-41')
{'pd1': (1.85, 84.0), 'pd2': (0.6900000000000001, 86.4)}
Accessing cached results from : 18-18-33
Failed fit at : 18-18-33
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('18-18-33', '18-19-25')
{'pd1': (1.85, 84.0), 'pd2': (0.6900000000000001, 85.6)}
Accessing cached results from : 18-20-18
Failed fit at : 18-20-18
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('18-20-18', '18-21-10')
{'pd1': (1.85, 84.0), 'pd2': (0.6900000000000001, 80.0)}
Accessing cached results from : 18-22-04
Failed fit at : 18-22-04
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('18-22-04', '18-22-56')
{'pd1': (1.85, 84.0), 'pd2': (0.6900000000000001, 84.0)}
Accessing cached results from : 18-23-50
Failed fit at : 18-23-50
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('18-23-50', '18-24-46')
{'pd1': (1.85, 84.0), 'pd2': (0.6900000000000001, 81.6)}
Accessing cached results from : 18-25-41
Failed fit at : 18-25-41
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('18-25-41', '18-26-35')
{'pd1': (1.85, 84.0), 'pd2': (0.6900000000000001, 83.2)}
Accessing cached results from : 18-27-30
Failed fit at : 18-27-30
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('18-27-30', '18-28-23')
{'pd1': (1.85, 84.0), 'pd2': (0.6900000000000001, 88.0)}
Accessing cached results from : 18-29-14
Failed fit at : 18-29-14
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('18-29-14', '18-30-07')
{'pd1': (1.85, 84.0), 'pd2': (0.6900000000000001, 87.2)}
Accessing cached results from : 18-30-58
Failed fit at : 18-30-58
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('18-30-58', '18-31-50')
{'pd1': (1.85, 84.0), 'pd2': (0.6900000000000001, 84.8)}
Accessing cached results from : 18-32-43
Failed fit at : 18-32-43
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('18-32-43', '18-33-33')
{'pd1': (1.85, 84.0), 'pd2': (1.705, 82.4)}
Accessing cached results from : 18-34-17
Failed fit at : 18-34-17
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('18-34-17', '18-35-01')
{'pd1': (1.85, 84.0), 'pd2': (1.705, 80.8)}
Accessing cached results from : 18-35-45
Failed fit at : 18-35-45
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('18-35-45', '18-36-37')
{'pd1': (1.85, 84.0), 'pd2': (1.705, 86.4)}
Accessing cached results from : 18-37-28
Failed fit at : 18-37-28
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('18-37-28', '18-38-22')
{'pd1': (1.85, 84.0), 'pd2': (1.705, 85.6)}
Accessing cached results from : 18-39-14
Failed fit at : 18-39-14
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('18-39-14', '18-40-07')
{'pd1': (1.85, 84.0), 'pd2': (1.705, 80.0)}
Accessing cached results from : 18-41-02
Failed fit at : 18-41-02
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('18-41-02', '18-41-55')
{'pd1': (1.85, 84.0), 'pd2': (1.705, 84.0)}
Accessing cached results from : 18-42-50
Failed fit at : 18-42-50
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('18-42-50', '18-43-45')
{'pd1': (1.85, 84.0), 'pd2': (1.705, 81.6)}
Accessing cached results from : 18-44-38
Failed fit at : 18-44-38
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('18-44-38', '18-45-32')
{'pd1': (1.85, 84.0), 'pd2': (1.705, 83.2)}
Accessing cached results from : 18-46-25
Failed fit at : 18-46-25
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('18-46-25', '18-47-18')
{'pd1': (1.85, 84.0), 'pd2': (1.705, 88.0)}
Accessing cached results from : 18-48-12
Failed fit at : 18-48-12
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('18-48-12', '18-49-06')
{'pd1': (1.85, 84.0), 'pd2': (1.705, 87.2)}
Accessing cached results from : 18-50-01
Failed fit at : 18-50-01
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('18-50-01', '18-50-54')
{'pd1': (1.85, 84.0), 'pd2': (1.705, 84.8)}
Accessing cached results from : 18-51-46
Failed fit at : 18-51-46
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('18-51-46', '18-52-38')
{'pd1': (1.85, 84.0), 'pd2': (0.4, 82.4)}
Accessing cached results from : 18-53-31
Failed fit at : 18-53-31
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('18-53-31', '18-54-26')
{'pd1': (1.85, 84.0), 'pd2': (0.4, 80.8)}
Accessing cached results from : 18-55-20
Failed fit at : 18-55-20
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('18-55-20', '18-56-14')
{'pd1': (1.85, 84.0), 'pd2': (0.4, 86.4)}
Accessing cached results from : 18-57-09
Failed fit at : 18-57-09
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('18-57-09', '18-58-04')
{'pd1': (1.85, 84.0), 'pd2': (0.4, 85.6)}
Accessing cached results from : 18-58-58
Failed fit at : 18-58-58
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('18-58-58', '18-59-53')
{'pd1': (1.85, 84.0), 'pd2': (0.4, 80.0)}
Accessing cached results from : 19-00-50
Failed fit at : 19-00-50
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('19-00-50', '19-01-45')
{'pd1': (1.85, 84.0), 'pd2': (0.4, 84.0)}
Accessing cached results from : 19-02-37
Failed fit at : 19-02-37
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('19-02-37', '19-03-30')
{'pd1': (1.85, 84.0), 'pd2': (0.4, 81.6)}
Accessing cached results from : 19-04-25
Failed fit at : 19-04-25
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('19-04-25', '19-05-18')
{'pd1': (1.85, 84.0), 'pd2': (0.4, 83.2)}
Accessing cached results from : 19-06-09
Failed fit at : 19-06-09
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('19-06-09', '19-07-03')
{'pd1': (1.85, 84.0), 'pd2': (0.4, 88.0)}
Accessing cached results from : 19-07-58
Failed fit at : 19-07-58
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('19-07-58', '19-08-50')
{'pd1': (1.85, 84.0), 'pd2': (0.4, 87.2)}
Accessing cached results from : 19-09-45
Failed fit at : 19-09-45
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('19-09-45', '19-10-40')
{'pd1': (1.85, 84.0), 'pd2': (0.4, 84.8)}
Accessing cached results from : 19-11-33
Failed fit at : 19-11-33
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('19-11-33', '19-12-26')
{'pd1': (1.85, 84.0), 'pd2': (0.9800000000000001, 82.4)}
Accessing cached results from : 19-13-21
Failed fit at : 19-13-21
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('19-13-21', '19-14-14')
{'pd1': (1.85, 84.0), 'pd2': (0.9800000000000001, 80.8)}
Accessing cached results from : 19-15-07
Failed fit at : 19-15-07
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('19-15-07', '19-15-58')
{'pd1': (1.85, 84.0), 'pd2': (0.9800000000000001, 86.4)}
Accessing cached results from : 19-16-53
Failed fit at : 19-16-53
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('19-16-53', '19-17-45')
{'pd1': (1.85, 84.0), 'pd2': (0.9800000000000001, 85.6)}
Accessing cached results from : 19-18-39
Failed fit at : 19-18-39
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('19-18-39', '19-19-32')
{'pd1': (1.85, 84.0), 'pd2': (0.9800000000000001, 80.0)}
Accessing cached results from : 19-20-25
Failed fit at : 19-20-25
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('19-20-25', '19-21-18')
{'pd1': (1.85, 84.0), 'pd2': (0.9800000000000001, 84.0)}
Accessing cached results from : 19-22-11
Failed fit at : 19-22-11
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('19-22-11', '19-23-06')
{'pd1': (1.85, 84.0), 'pd2': (0.9800000000000001, 81.6)}
Accessing cached results from : 19-23-58
Failed fit at : 19-23-58
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('19-23-58', '19-24-50')
{'pd1': (1.85, 84.0), 'pd2': (0.9800000000000001, 83.2)}
Accessing cached results from : 19-25-42
Failed fit at : 19-25-42
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('19-25-42', '19-26-32')
{'pd1': (1.85, 84.0), 'pd2': (0.9800000000000001, 88.0)}
Accessing cached results from : 19-27-24
Failed fit at : 19-27-24
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('19-27-24', '19-28-17')
{'pd1': (1.85, 84.0), 'pd2': (0.9800000000000001, 87.2)}
Accessing cached results from : 19-29-10
Failed fit at : 19-29-10
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('19-29-10', '19-30-04')
{'pd1': (1.85, 84.0), 'pd2': (0.9800000000000001, 84.8)}
Accessing cached results from : 19-30-56
Failed fit at : 19-30-56
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('19-30-56', '19-31-49')
{'pd1': (1.85, 84.0), 'pd2': (0.8350000000000001, 82.4)}
Accessing cached results from : 19-32-43
Failed fit at : 19-32-43
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('19-32-43', '19-33-39')
{'pd1': (1.85, 84.0), 'pd2': (0.8350000000000001, 80.8)}
Accessing cached results from : 19-34-31
Failed fit at : 19-34-31
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('19-34-31', '19-35-25')
{'pd1': (1.85, 84.0), 'pd2': (0.8350000000000001, 86.4)}
Accessing cached results from : 19-36-19
Failed fit at : 19-36-19
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('19-36-19', '19-37-13')
{'pd1': (1.85, 84.0), 'pd2': (0.8350000000000001, 85.6)}
Accessing cached results from : 19-38-05
Failed fit at : 19-38-05
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('19-38-05', '19-38-59')
{'pd1': (1.85, 84.0), 'pd2': (0.8350000000000001, 80.0)}
Accessing cached results from : 19-39-54
Failed fit at : 19-39-54
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('19-39-54', '19-40-47')
{'pd1': (1.85, 84.0), 'pd2': (0.8350000000000001, 84.0)}
Accessing cached results from : 19-41-43
Failed fit at : 19-41-43
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('19-41-43', '19-42-38')
{'pd1': (1.85, 84.0), 'pd2': (0.8350000000000001, 81.6)}
Accessing cached results from : 19-43-34
Failed fit at : 19-43-34
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('19-43-34', '19-44-27')
{'pd1': (1.85, 84.0), 'pd2': (0.8350000000000001, 83.2)}
Accessing cached results from : 19-45-18
Failed fit at : 19-45-18
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('19-45-18', '19-46-12')
{'pd1': (1.85, 84.0), 'pd2': (0.8350000000000001, 88.0)}
Accessing cached results from : 19-47-08
Failed fit at : 19-47-08
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('19-47-08', '19-48-02')
{'pd1': (1.85, 84.0), 'pd2': (0.8350000000000001, 87.2)}
Accessing cached results from : 19-48-55
Failed fit at : 19-48-55
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('19-48-55', '19-49-51')
{'pd1': (1.85, 84.0), 'pd2': (0.8350000000000001, 84.8)}
Accessing cached results from : 19-50-43
Failed fit at : 19-50-43
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('19-50-43', '19-51-37')
{'pd1': (1.85, 84.0), 'pd2': (1.415, 82.4)}
Accessing cached results from : 19-52-32
Failed fit at : 19-52-32
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('19-52-32', '19-53-26')
{'pd1': (1.85, 84.0), 'pd2': (1.415, 80.8)}
Accessing cached results from : 19-54-20
Failed fit at : 19-54-20
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('19-54-20', '19-55-13')
{'pd1': (1.85, 84.0), 'pd2': (1.415, 86.4)}
Accessing cached results from : 19-56-07
Failed fit at : 19-56-07
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('19-56-07', '19-57-02')
{'pd1': (1.85, 84.0), 'pd2': (1.415, 85.6)}
Accessing cached results from : 19-57-56
Failed fit at : 19-57-56
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('19-57-56', '19-58-49')
{'pd1': (1.85, 84.0), 'pd2': (1.415, 80.0)}
Accessing cached results from : 19-59-43
Failed fit at : 19-59-43
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('19-59-43', '20-00-35')
{'pd1': (1.85, 84.0), 'pd2': (1.415, 84.0)}
Accessing cached results from : 20-01-27
Failed fit at : 20-01-27
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-01-27', '20-02-23')
{'pd1': (1.85, 84.0), 'pd2': (1.415, 81.6)}
Accessing cached results from : 20-03-16
Failed fit at : 20-03-16
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-03-16', '20-04-08')
{'pd1': (1.85, 84.0), 'pd2': (1.415, 83.2)}
Accessing cached results from : 20-05-01
Failed fit at : 20-05-01
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-05-01', '20-05-44')
{'pd1': (1.85, 84.0), 'pd2': (1.415, 88.0)}
Accessing cached results from : 20-06-28
Failed fit at : 20-06-28
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-06-28', '20-07-12')
{'pd1': (1.85, 84.0), 'pd2': (1.415, 87.2)}
Accessing cached results from : 20-07-55
Failed fit at : 20-07-55
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-07-55', '20-08-39')
{'pd1': (1.85, 84.0), 'pd2': (1.415, 84.8)}
Accessing cached results from : 20-09-22
Failed fit at : 20-09-22
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-09-22', '20-10-06')
{'pd1': (1.85, 84.0), 'pd2': (0.545, 82.4)}
Accessing cached results from : 20-10-49
Failed fit at : 20-10-49
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-10-49', '20-11-33')
{'pd1': (1.85, 84.0), 'pd2': (0.545, 80.8)}
Accessing cached results from : 20-12-17
Failed fit at : 20-12-17
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-12-17', '20-13-01')
{'pd1': (1.85, 84.0), 'pd2': (0.545, 86.4)}
Accessing cached results from : 20-13-44
Failed fit at : 20-13-44
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-13-44', '20-14-28')
{'pd1': (1.85, 84.0), 'pd2': (0.545, 85.6)}
Accessing cached results from : 20-15-12
Failed fit at : 20-15-12
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-15-12', '20-15-55')
{'pd1': (1.85, 84.0), 'pd2': (0.545, 80.0)}
Accessing cached results from : 20-16-39
Failed fit at : 20-16-39
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-16-39', '20-17-24')
{'pd1': (1.85, 84.0), 'pd2': (0.545, 84.0)}
Accessing cached results from : 20-18-07
Failed fit at : 20-18-07
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-18-07', '20-18-51')
{'pd1': (1.85, 84.0), 'pd2': (0.545, 81.6)}
Accessing cached results from : 20-19-35
Failed fit at : 20-19-35
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-19-35', '20-20-19')
{'pd1': (1.85, 84.0), 'pd2': (0.545, 83.2)}
Accessing cached results from : 20-21-02
Failed fit at : 20-21-02
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-21-02', '20-21-47')
{'pd1': (1.85, 84.0), 'pd2': (0.545, 88.0)}
Accessing cached results from : 20-22-32
Failed fit at : 20-22-32
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-22-32', '20-23-18')
{'pd1': (1.85, 84.0), 'pd2': (0.545, 87.2)}
Accessing cached results from : 20-24-04
Failed fit at : 20-24-04
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-24-04', '20-24-50')
{'pd1': (1.85, 84.0), 'pd2': (0.545, 84.8)}
Accessing cached results from : 20-25-34
Failed fit at : 20-25-34
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-25-34', '20-26-20')
{'pd1': (1.85, 84.0), 'pd2': (1.27, 82.4)}
Accessing cached results from : 20-27-05
Failed fit at : 20-27-05
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-27-05', '20-27-51')
{'pd1': (1.85, 84.0), 'pd2': (1.27, 80.8)}
Accessing cached results from : 20-28-39
Failed fit at : 20-28-39
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-28-39', '20-29-29')
{'pd1': (1.85, 84.0), 'pd2': (1.27, 86.4)}
Accessing cached results from : 20-30-22
Failed fit at : 20-30-22
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-30-22', '20-31-20')
{'pd1': (1.85, 84.0), 'pd2': (1.27, 85.6)}
Accessing cached results from : 20-32-12
Failed fit at : 20-32-12
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-32-12', '20-33-07')
{'pd1': (1.85, 84.0), 'pd2': (1.27, 80.0)}
Accessing cached results from : 20-33-57
Failed fit at : 20-33-57
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-33-57', '20-34-48')
{'pd1': (1.85, 84.0), 'pd2': (1.27, 84.0)}
Accessing cached results from : 20-35-41
Failed fit at : 20-35-41
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-35-41', '20-36-35')
{'pd1': (1.85, 84.0), 'pd2': (1.27, 81.6)}
Accessing cached results from : 20-37-26
Failed fit at : 20-37-26
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-37-26', '20-38-18')
{'pd1': (1.85, 84.0), 'pd2': (1.27, 83.2)}
Accessing cached results from : 20-39-08
Failed fit at : 20-39-08
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-39-08', '20-39-58')
{'pd1': (1.85, 84.0), 'pd2': (1.27, 88.0)}
Accessing cached results from : 20-40-50
Failed fit at : 20-40-50
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-40-50', '20-41-42')
{'pd1': (1.85, 84.0), 'pd2': (1.27, 87.2)}
Accessing cached results from : 20-42-28
Failed fit at : 20-42-28
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-42-28', '20-43-15')
{'pd1': (1.85, 84.0), 'pd2': (1.27, 84.8)}
Accessing cached results from : 20-44-02
Failed fit at : 20-44-02
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-44-02', '20-44-50')
{'pd1': (1.85, 84.0), 'pd2': (1.56, 82.4)}
Accessing cached results from : 20-45-40
Failed fit at : 20-45-40
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-45-40', '20-46-29')
{'pd1': (1.85, 84.0), 'pd2': (1.56, 80.8)}
Accessing cached results from : 20-47-19
Failed fit at : 20-47-19
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-47-19', '20-48-09')
{'pd1': (1.85, 84.0), 'pd2': (1.56, 86.4)}
Accessing cached results from : 20-49-00
Failed fit at : 20-49-00
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-49-00', '20-49-52')
{'pd1': (1.85, 84.0), 'pd2': (1.56, 85.6)}
Accessing cached results from : 20-50-43
Failed fit at : 20-50-43
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-50-43', '20-51-33')
{'pd1': (1.85, 84.0), 'pd2': (1.56, 80.0)}
Accessing cached results from : 20-52-23
Failed fit at : 20-52-23
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-52-23', '20-53-13')
{'pd1': (1.85, 84.0), 'pd2': (1.56, 84.0)}
Accessing cached results from : 20-54-03
Failed fit at : 20-54-03
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-54-03', '20-54-56')
{'pd1': (1.85, 84.0), 'pd2': (1.56, 81.6)}
Accessing cached results from : 20-55-47
Failed fit at : 20-55-47
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-55-47', '20-56-40')
{'pd1': (1.85, 84.0), 'pd2': (1.56, 83.2)}
Accessing cached results from : 20-57-31
Failed fit at : 20-57-31
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-57-31', '20-58-23')
{'pd1': (1.85, 84.0), 'pd2': (1.56, 88.0)}
Accessing cached results from : 20-59-12
Failed fit at : 20-59-12
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-59-12', '20-59-57')
{'pd1': (1.85, 84.0), 'pd2': (1.56, 87.2)}
Accessing cached results from : 21-00-42
Failed fit at : 21-00-42
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('21-00-42', '21-01-27')
{'pd1': (1.85, 84.0), 'pd2': (1.56, 84.8)}
Accessing cached results from : 21-02-12
Failed fit at : 21-02-12
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('21-02-12', '21-02-56')
{'pd1': (1.85, 84.0), 'pd2': (1.85, 82.4)}
Accessing cached results from : 21-03-41
Failed fit at : 21-03-41
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('21-03-41', '21-04-25')
{'pd1': (1.85, 84.0), 'pd2': (1.85, 80.8)}
Accessing cached results from : 21-05-09
Failed fit at : 21-05-09
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('21-05-09', '21-05-53')
{'pd1': (1.85, 84.0), 'pd2': (1.85, 86.4)}
Accessing cached results from : 21-06-37
Failed fit at : 21-06-37
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('21-06-37', '21-07-20')
{'pd1': (1.85, 84.0), 'pd2': (1.85, 85.6)}
Accessing cached results from : 21-08-04
Failed fit at : 21-08-04
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('21-08-04', '21-08-57')
{'pd1': (1.85, 84.0), 'pd2': (1.85, 80.0)}
Accessing cached results from : 21-09-50
Failed fit at : 21-09-50
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('21-09-50', '21-10-43')
{'pd1': (1.85, 84.0), 'pd2': (1.85, 84.0)}
Accessing cached results from : 21-11-36
Failed fit at : 21-11-36
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('21-11-36', '21-12-29')
{'pd1': (1.85, 84.0), 'pd2': (1.85, 81.6)}
Accessing cached results from : 21-13-13
Failed fit at : 21-13-13
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('21-13-13', '21-13-57')
{'pd1': (1.85, 84.0), 'pd2': (1.85, 83.2)}
Accessing cached results from : 21-14-41
Failed fit at : 21-14-41
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('21-14-41', '21-15-24')
{'pd1': (1.85, 84.0), 'pd2': (1.85, 88.0)}
Accessing cached results from : 21-16-08
Failed fit at : 21-16-08
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('21-16-08', '21-16-52')
{'pd1': (1.85, 84.0), 'pd2': (1.85, 87.2)}
Accessing cached results from : 21-17-36
Failed fit at : 21-17-36
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('21-17-36', '21-18-19')
{'pd1': (1.85, 84.0), 'pd2': (1.85, 84.8)}
Accessing cached results from : 21-19-03
Failed fit at : 21-19-03
Traceback (most recent call last):
  File "<ipython-input-42-40d6a8b7fbcd>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-42-40d6a8b7fbcd>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('21-19-03', '21-19-47')
Out[ ]:
In [ ]:
import os
import sys
from functools import partial
sys.path.append(os.path.join(os.getcwd(), '..')) #adds directory below as valid path
from  datetime import datetime, timedelta
dateformat = "%H-%M-%S"
from collections import deque
import traceback
from multiprocessing import Pool
from tqdm import tqdm

import scipy.constants as spc
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd

plt.rcParams['axes.grid'] = True
plt.rcParams['grid.linestyle'] = '--'

from MT_class_PID_new import MTdataHost
from global_folder.myplotsty import *
from global_folder.my_helpers import *

PUMP_FREQUENCY = 384228.6
REPUMP_FREQUENCY = 384228.6 + 6.56
SAMPLE_RATE = 2000
FREQVSVOLT = 221.0 
FREQVSCURR = 1.13

# TODO: find a better place for this
EXP_FOLDER =r'C:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\CATMeasurements'
MEASURE_FOLDER = os.path.join(EXP_FOLDER, 'testPArun16')
WDATA_FOLDER =os.path.join(MEASURE_FOLDER, 'testPArun16.csv')

# TODO: maybe make a run analysis class out of this?
def dump():
	fig, ax = plt.subplots()
	plot_results(ax, df, max_freq= 384219., fmt='o', mfc='red', save_folder=MEASURE_FOLDER)
	plt.savefig(os.path.join(MEASURE_FOLDER, 'ratio_vs_freq.png'))

	
	collect_plots(MEASURE_FOLDER, os.path.join(MEASURE_FOLDER, 'collected_plots'), 'deloadPhase.png')
 
	#*-----------------------
	#* SINGLE RUN
 	#*----------------------- 
  
	MEASURE_FOLDER = os.path.join(EXP_FOLDER, 'testPArun9')
	df = get_data_frame(MEASURE_FOLDER)
	df.dropna(inplace=True)
	#freqs = plot_results(df, 384201., save_folder=MEASURE_FOLDER)
 
	data = df.dropna()
	freqs = ((384201-PUMP_FREQUENCY)-(data['tempV']-df['tempV'].min())*FREQVSVOLT- (data['currV']-df['currV'].min())*FREQVSCURR)
	fig, ax = plt.subplots()
	plot_spline_fit(ax=ax, x=freqs, y=data['ratio'], yerr=data['ratioErr'], 
				 s=0.1, save_folder=MEASURE_FOLDER, 
				 mfc='red', color='black', 
				 title='Trap Depth = 1.99 K')
 
	# *-----------------------
	# * MULTIPLE RUN COMPARISON
 	# *-----------------------
	folders = [os.path.join(EXP_FOLDER, path ) for path in ['testPARun11', 'testPARun12', 'testPARun13', 'testPARun14']]
	dfs = [get_data_frame(measure_folder, cache_all=True) for measure_folder in folders]

	colors = ['red', 'dodgerblue', 'green', 'grey']
	max_freqs = [384178.881, 384178.593,384179.068, 384184.731]
	#max_freqs=[384178.599, 384179.091, 384184.733]

	zipped_data = list(zip(dfs, max_freqs))
	fig, ax = plt.subplots()
	for i, (df, max_freq)  in enumerate(zipped_data[:3]):
		data = df.dropna()
		freqs = ((max_freq-PUMP_FREQUENCY)-(data['tempV']-data['tempV'].min())*FREQVSVOLT- (data['currV']-data['currV'].min())*FREQVSCURR)
		color = colors[i]
		ax=plot_spline_fit(ax, x=freqs, y=data['ratio'], scolor=color, mfc=color,color=color, s=0.02, ms=5)

	#*-----------------------
	#* PARSING WAVEMETER DATA
 	#*-----------------------

	MEASURE_FOLDER = os.path.join(EXP_FOLDER, 'testPArun14')
	WDATA_FOLDER =os.path.join(MEASURE_FOLDER, 'testPArun14.csv')
	freq_data, max_freq, min_freq = add_wavemeter_data('', WDATA_FOLDER)
	data = freq_data[:]
	levels = staircase_fit(data)

	data = get_data_frame(MEASURE_FOLDER)
	data.dropna(inplace=True)
	freqs = ((max_freq)-(data['tempV']-data['tempV'].min())*FREQVSVOLT- (data['currV']-data['currV'].min())*FREQVSCURR)
	plt.plot(freqs)
 
	#*-----------------------
	#* GETTING DEPTH_RATIO DATAFRAME
 	#*-----------------------
	MEASURE_FOLDER = r'C:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\CATMeasurements\relScatRate'
	depth_ratios_df = get_rel_scattering_df(MEASURE_FOLDER)
	df_slice = depth_ratios_df[(depth_ratios_df['pa1']==1.85) & (depth_ratios_df['pd1']==84) & (depth_ratios_df['pd2'] == 84)]
	x = df_slice['pa2']
	y = df_slice['depth_ratio']
	plt.plot(x,y, 'o')

	#*-----------------------
	#* MEGA_RUN
 	#*-----------------------	
	MEASURE_FOLDER = os.path.join(EXP_FOLDER, 'testPARunMega')
	df = get_data_frame(MEASURE_FOLDER)
	df.dropna(inplace=True)

	df_grouped = df.groupby(by='pump_reference')
	min_ratios = df_grouped['ratio'].min()

	groups = dict(list(df_grouped))
	dfs = [df for df in groups.values()]
 
	max_freqs = [384182.5]*15
	#max_freqs=[384178.599, 384179.091, 384184.733]
	zipped_data = list(zip(dfs, max_freqs))
	fig, ax = plt.subplots()
	for i, (df, max_freq)  in enumerate(zipped_data[:]):
		data = df.dropna()
		freqs = ((max_freq-PUMP_FREQUENCY)-(data['tempV']-data['tempV'].min())*FREQVSVOLT- (data['currV']-data['currV'].min())*FREQVSCURR)
		ax=plot_spline_fit(ax, x=freqs, y=data['ratio'], yerr=data['ratioErr'],scolor=f'C{i}', mfc=f'C{i}',color=f'C{i}', s=0.0, ms=5, figsize=(10, 10), label=f"Pump Amplituide = { df.iloc[10]['pump_reference'] :.2f}", linewidth=2.5)

	plt.legend()

	plt.savefig(os.path.join(MEASURE_FOLDER, 'lossFeatures.png'))
	#*-----------------------
	#* MULTIPLE MEGARUN
	#*-----------------------
 
	folders = [os.path.join(EXP_FOLDER, path ) for path in ['testPArunMega', 'testPArunMega2']]
	dfs_mega = [get_data_frame(measure_folder, cache_all=True).dropna() for measure_folder in folders]

	dfs_grouped = [df_mega.groupby(by='pump_reference') for df_mega in dfs_mega]
	min_ratios = [df_grouped['ratio'].min() for df_grouped in dfs_grouped]

	groupss = [dict(list(df_grouped)) for df_grouped in dfs_grouped]
	dfs = [ [df for df in groups.values()] for groups in groupss]
 
	for row in dfs:
		x = [df['pump_reference'].mean() for df in row]
		y = [(df['ratio'].max() - df['ratio'].min())/df['motSS'].std() for df in row]
		plt.plot( x, y ,'-o', label=fr"$\delta$ = {180 - 2*row[0]['pump_AOM_freq'].mean()} MHz")
		plt.xlabel('Pump Amplitude')
		plt.ylabel(r'SNR $ = \frac{V_{ss, off} - V_{ss, on}}{\sigma_{V,off}}$ ')
	plt.legend()

def freq_misc():
	WDATA_FOLDER = r'C:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\CATMeasurements\CATcurrTestrun3.csv'
	freq_data = add_wavemeter_data('', WDATA_FOLDER)
	levels = staircase_fit(freq_data[0], peak_height=0.2, distance=50, data_offset=1, window_size=1) 

	plt.close()
 
	x = np.linspace(0, 4.9, 25)
	y = levels
 
	plt.plot(levels, '-o')
	plt.title('Levels plot')
	
	m, b, fit_line = my_linear_fit(x, y)
def save_fit_results(run_path, plot=False):
	filename = os.path.join(run_path, 'data.csv')
	bkfilename = os.path.join(run_path, 'data_oldPD.csv')
	settingsname = os.path.join(run_path, 'Settings.txt')
	
	dataHost = MTdataHost(SAMPLE_RATE)
	dataHost.loadCATdata(fileName=filename, settingsName=settingsname)
	dataHost.CATbackgroundData(bkfilename)
	
	dataHost.setAllCAT(0.002)
	resultDict = dataHost.getResults(run_path, store=True)
 
	if plot:
		dataHost.storeFits(run_path, combined=True, separate=True)
  
	return resultDict, dataHost.settings
		
def get_timestamp(run_path):
	timestamp = datetime.strptime(os.path.split(run_path)[-1].split('_')[0], dateformat)
	return timestamp

def extract_fit(run_path, plot=True, cache_failed=True, cache_all=True):
	"""Gather relevant data from each measurement run

	Args:
		run_path : absolute path to the run directory
		plot (bool, optional): plot fits. Defaults to True.
		cache_failed (bool, optional): Cache failed fits. If false, refit. Doesn't refit non-failed fits. Defaults to True.
		cache_all (bool, optional): If false, ignore any cached fit_results. Defaults to True.

	Returns:
		a 3-tuple (fit_results, settings, timestamp)
	"""
	fit_results, settings, timestamp = {}, {}, None
	
	if not os.path.isdir(run_path):
		return fit_results, settings, timestamp  # directory is not a run directory

	try:
		timestamp = get_timestamp(run_path)
  
  	# TODO: specify which error to catch
	except Exception as e:
		print("Error extracting timestamp from: ", run_path)
		print(traceback.format_exc())
	
	MAT_fit_cache_path = os.path.join(run_path, 'resultDict.txt')
 
	if not os.path.exists(MAT_fit_cache_path) or not cache_all:
		
		try: 
			fit_results, settings = save_fit_results(run_path, plot=plot)
		except Exception as e:
			print(traceback.format_exc())
			print("Fitting ERROR at ", os.path.basename(run_path), '\n')

			with open(MAT_fit_cache_path, 'w') as f:
				f.write(str('MAT fit failed'))
		
	else:
		print("Accessing cached results from :", os.path.basename(run_path))
  
		fit_results = open(MAT_fit_cache_path, 'r').read()

		if fit_results == 'MAT fit failed':
			if not cache_failed:
				# fit regardless of cached result
				try: 
					fit_results, settings = save_fit_results(run_path, plot=plot)
				except Exception as e:
					print(traceback.format_exc())
					print("Fitting ERROR at ", os.path.basename(run_path), '\n')
	
					with open(MAT_fit_cache_path, 'w') as f:
						f.write(str('MAT fit failed'))	
			else:
				print("Failed fit at :", os.path.basename(run_path))
				fit_results = {}

		else:
			fit_results = eval(open(MAT_fit_cache_path, 'r').read())
   
			settingsname = os.path.join(run_path, 'Settings.txt')
			settings = eval(open(settingsname, 'r').read())
   
	return fit_results, settings, timestamp



def get_row(run_path, **kwargs):
			
   fit_results, settings, timestamp = extract_fit(run_path, **kwargs)
   row = {**fit_results, **settings, **{'timestamp':timestamp}}
   
   return row

   
def get_data_frame(data_dir, parallel=True, in_process_run=False, **kwargs):
   
	run_path_arr = []
	rows = []
	
	for relative_path in os.listdir(data_dir):
		run_path_arr.append(os.path.join(data_dir, relative_path))
  
	if in_process_run:
		run_path_arr.pop()

	run_path_arr = sorted(run_path_arr)
	
	if parallel:
		with Pool(4) as p:
			rows = list(tqdm(p.imap(partial(get_row, **kwargs), run_path_arr), total=len(run_path_arr)))
	
	else:
		for run_path in tqdm(run_path_arr):
		   rows.append(get_row(run_path, **kwargs))

	return pd.DataFrame.from_dict(rows)

def add_wavemeter_data(df, wmeter_csv_path, window_size=100, num_rows=50):


	"""Extract unique frequnecy values from wavemeter data
	Returns:
		unique_levels (list): unique frequency values in wavemeter data
	"""
 
	# TODO: modify dataframe in place with frequency data
 
	wdata = pd.read_csv(wmeter_csv_path, skiprows=2)
	wdata.dropna(inplace=True)
	freq_data = np.array(wdata.iloc[:, 0])
	try:
		freq_data = np.array([float(item) for item in freq_data if item.replace('.','').isdigit()])
	except Exception as e:
		print(e)
 
	max_freq = freq_data.max()
	min_freq = freq_data.min()

	return freq_data, max_freq, min_freq

def plot_results(ax, dfs, max_freq, min_freq=0.0, mfc='red', fmt='o', ms=5, save_folder=False, xscale=1.0, yscale=1.0, **kwargs):
	FREQVSVOLT = 221.0 
	FREQVSCURR = 1.13
	
	if not type(dfs) == list:
		freqs = ((max_freq-PUMP_FREQUENCY)-(dfs.dropna()['tempV']-dfs.dropna()['tempV'].min())*FREQVSVOLT- (dfs.dropna()['currV']-dfs.dropna()['currV'].min())*FREQVSCURR)*xscale
		dfs=[dfs]
  
	plt.gcf().set_dpi(300)
	
	for df in dfs:
		df = df.dropna()
		ax.errorbar(freqs, 
			   df['ratio']*yscale,
			   yerr=df['ratioErr'],
			   fmt=fmt, mfc=mfc, color='black', ms=ms, **kwargs)
		ax.set_ylabel(r'$\mathbf{\frac{V_{ss, cat}}{V_{ss}}} $ ', **labeldict)
		ax.set_xlabel(r'$\Delta $ (GHz)', **labeldict)
	
	if save_folder:
		plt.savefig(os.path.join(save_folder, 'ratio_vs_freq.png'))
	
	return freqs, ax
  
	#return plt.gca(), plt.gcf()
	#plt.show()

def plot_spline_fit(ax, x, y, s=1, yerr=None, color='black', scolor='black',figsize=(12,5), save_folder=None, title='',alpha=0.5,dpi=200, label='plot',**kwargs):
	from scipy.interpolate import splev, splrep
	xnew = np.linspace(min(x), max(x), 3*len(x) )

	y = [b for a,b in sorted(zip(x,y), key=lambda pair: pair[0])]
	if yerr is not None:
		yerr = [b for a,b in sorted(zip(x,yerr), key=lambda pair: pair[0])]
 
	x = sorted(x)

	spl = splrep(x, y, s=s)
	ynew = splev(xnew, spl)

	
	plt.gcf().set_dpi(dpi)
	plt.gcf().set_size_inches(figsize)
	
	if yerr is not None:
		ax.errorbar(x, y, yerr=yerr, fmt='o', **kwargs)
	else:
		ax.plot(x,y, 'o', **kwargs)
	ax.plot(xnew, ynew, '-', color=scolor, alpha=alpha, label=label, **kwargs)
 
	ax.set_ylabel(r'$\mathbf{\frac{V_{ss, cat}}{V_{ss}}} $ ', **labeldict)
	ax.set_xlabel(r'$\Delta $ (GHz)', **labeldict)
 
	ax.set_title(title, **titledict)
	if save_folder:
		plt.savefig(os.path.join(save_folder, 'spline_ratio_vs_freq.png'))
	
	return ax
 
def plot_polyfit(x_data, y_data, spline_degree):
	
	coefficients = np.polyfit(x_data, y_data, spline_degree)

	x_interp = np.linspace(min(x_data), max(x_data), 100)
	y_interp = np.polyval(coefficients, x_interp)

	plt.scatter(x_data, y_data, label='Original Data')
	plt.plot(x_interp, y_interp, label='Polynomial Interpolation (Degree={})'.format(spline_degree))

def collect_plots(source, destination, plot_name):
	print(f'Collecting plots from {os.path.basename(source)}')
	import shutil

	os.makedirs(destination, exist_ok=True)

	plot_files = []
	for root, dirs, files in os.walk(source):
		
		for file in files:
			if file == plot_name:
				plot_files.append(os.path.join(root, file))

	for i, plot_file in enumerate(plot_files, start=0):
		new_filename = f'{i}{plot_name}'
		destination_path = os.path.join(destination, new_filename)
		shutil.copy(plot_file, destination_path)

def create_GIF(images_folder, image_name):
	import imageio
	with imageio.get_writer(os.path.join(images_folder, f'{image_name}movie.gif'), mode='I', duration=0.5) as writer:
		for filename in os.listdir(images_folder):
			if image_name in filename:
				image = imageio.imread(os.path.join(images_folder, filename))
				writer.append_data(image)

def staircase_fit(data, peak_height=0.1, distance=100, data_offset=1, window_size=1, inc_final_peak=True):
	def moving_average(arr, window_size):
		weights = np.ones(window_size) / window_size
		return np.convolve(arr, weights, mode='valid')

	convdata1 = moving_average(data, window_size)
	convdata2 = moving_average(data[data_offset+1:], window_size )
	final = convdata1[:len(convdata2)]-convdata2
	# plt.plot(data)
	# plt.plot(convdata1)
	# plt.plot(convdata2)
	# plt.show()
	# plt.plot(final)

	
	from scipy.signal import find_peaks
	x= final
	peaks, _ = find_peaks(x, height=peak_height, distance=distance)
	peaks = np.insert(peaks, 0, 0)
	levels = []
	plot_arr = []
	for i, peak in enumerate(peaks):
		
		if i < len(peaks) - 1:
			temp = data[ peaks[i]:peaks[i+1] ]
			plot_arr.extend( np.ones_like(temp)*np.mean(temp))
			levels.append(np.mean(temp))
	if inc_final_peak:
		temp = data[peaks[-1]:]
		levels.append(np.mean(temp))
		plot_arr.extend( np.ones_like(temp)*np.mean(temp))
  
	plt.plot(x)
	plt.plot(peaks, x[peaks], "x")
	plt.plot(np.zeros_like(x), "--", color="gray")
	plt.show()
	
	plt.plot(data)
	plt.plot(np.ravel((plot_arr)))
	plt.show()
	plt.close()
	plt.plot(np.array(levels)[np.where(abs(np.diff(levels))>0.05)[0]], 'o', ms=5)
 
	return levels

def load_single_run(run_path):
	filename = os.path.join(run_path, 'data.csv')
	bkfilename = os.path.join(run_path, 'data_oldPD.csv')
	settingsname = os.path.join(run_path, 'Settings.txt')
	
	dh1 = MTdataHost(SAMPLE_RATE)
	dh1.loadCATdata(fileName=filename, settingsName=settingsname)
	
	return dh1
	# *-----------------------
	# *RELATIVE SCATTERING RATE
	# *-----------------------


def get_rel_scattering_df(data_folder):
	depth_ratios_df = []
	listdir = sorted(os.listdir(data_folder))
	try:
		for run_folder1, run_folder2 in [listdir[i:i+2] for i in range(len(listdir))[::2]]:
			try:
				run_path1 = os.path.join(data_folder, run_folder1)
				run_path2 = os.path.join(data_folder, run_folder2)
				result = {}
				with open(os.path.join(run_path1, 'twoSettings.txt'), 'r') as f:
					settings = f.read() 
					import re

					pattern = r'(\w+)\s*=\s*\(([\d.]+),\s*([\d.]+)\)'

					matches = re.findall(pattern, settings)

					
					for match in matches:
						key = match[0]
						value1 = float(match[1])
						value2 = float(match[2])
						result[key] = (value1, value2)

					print(result)
				with open(os.path.join(run_path2, 'twoSettings.txt'), 'r') as f:
					pass
					#print(f.readlines())
				
				timestamp = get_timestamp(run_path)
				fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
				
				extracted_values = {
						'pa1': result['pd1'][0],
						'pd1': result['pd1'][1],
						'pa2': result['pd2'][0],
						'pd2': result['pd2'][1],
						'depth_ratio': 1/float(depth_ratio), # ratio between current and std settings
      					'timestamp': timestamp
					}
				depth_ratios_df.append(extracted_values)
				
				print('\n')
			except Exception as e:
					print(traceback.format_exc())
					print(f'Error {e} at {run_folder1, run_folder2}')
	except Exception as e:
		print(f'Error {e}')

	depth_ratios_df = pd.DataFrame(depth_ratios_df)
 
	return depth_ratios_df

def get_rel_scattering(run_path1, run_path2):
	resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
	resultDict2, scat_ratio2 = _load_single_run_rel_scat(run_path2, plot=True)
	
	print(f"scat_ratio 1, (2 inverted) = {scat_ratio1:.3f}, {1/scat_ratio2:.3f}")
	scat_ratio_avg = (scat_ratio1+1/scat_ratio2)/2
	
	Rratio = resultDict1['initMOTR']/resultDict2['initMOTR']
	print(fr"Rratio = {resultDict1['initMOTR']:.3f} / {resultDict2['initMOTR']:.3f} = {Rratio:.3f}")
	depthRatio = np.sqrt(Rratio/scat_ratio_avg)
	
	return resultDict1, resultDict2, depthRatio


def _load_single_run_rel_scat(run_path, plot=False, cache_all=False):
	filename = os.path.join(run_path, 'data.csv')
	settingsname = os.path.join(run_path, 'Settings.txt')
	
	MAT_fit_cache_path = os.path.join(run_path, 'resultDict.txt')
	fit_results = {}
	if not os.path.exists(MAT_fit_cache_path) or not cache_all:
		
		try: 
			dh1 = MTdataHost(SAMPLE_RATE)
			dh1.loadCATdata(fileName=filename, settingsName=settingsname)

			dh1.tBaseline = 1
			dh1.tLoad = 2
			dh1.timeLoad = 30
			dh1.tReload = dh1.tLoad + dh1.timeLoad
			dh1.timeReload = 1
			dh1.tCATbackground = dh1.tReload + dh1.timeReload

			dh1.setOffset()
			dh1.setCATtiming()
			dh1.setAllCAT(0.002)

			print('FITTINGGGGGGGGGGGG')
			fit_results = dh1.getResults(run_path, store=True)
			if plot:
				dh1.storeFits(run_path, combined=True, separate=False)
		except Exception as e:
			print(traceback.format_exc())
			print("Fitting ERROR at ", os.path.basename(run_path), '\n')

			with open(MAT_fit_cache_path, 'w') as f:
				f.write(str('MAT fit failed'))
		
	else:
		print("Accessing cached results from :", os.path.basename(run_path))

		fit_results = open(MAT_fit_cache_path, 'r').read()

		if fit_results == 'MAT fit failed':
			print("Failed fit at :", os.path.basename(run_path))
			fit_results = {}

		else:
			fit_results = eval(open(MAT_fit_cache_path, 'r').read())


	
	scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
	fit_results['scat_ratio'] = scat_ratio
 	#scat_ratio = dh1.motSS/(dh1.reloadVolt+dh1.baseVolt - (dh1.CATbackgroundVolt+dh1.noLightBackground))
	
	return fit_results, scat_ratio

def scat_rate(I, delta, gamma=6.065, Is=1.669):
	"""_summary_

	Args:
		I (float): intensity (Mhz)
		delta (float): detuning (Mhz)
		gamma (float, optional): linewidth (Mhz) Defaults to 6.065.
		Is (float, optional): Should be one of 3.576(isotropic), 2.503(pi), 1.669 (sigma+-). Defaults to 1.669.

	Returns:
		_type_: gamma: the scattering rate
	"""
	return gamma*I/(2*Is*(1+I/Is+4*(delta/gamma)**2))

if __name__ == '__main__':
	run_path = r"C:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\CATMeasurements\testPArun9\16-53-10"
	filename = os.path.join(run_path, 'data.csv')
	bkfilename = os.path.join(run_path, 'data_oldPD.csv')
	settingsname = os.path.join(run_path, 'Settings.txt')
	
	dh1 = MTdataHost(SAMPLE_RATE)
	dh1.loadCATdata(fileName=filename, settingsName=settingsname)
	
 	#dh1.CATbackgroundData(bkfilename)
	dh1.setAllCAT(0.002)
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
In [ ]:
get_rel_scattering_df(r'C:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\CATMeasurements\relScatRate\TrapDepthMap')
{'pd1': (1.85, 84.0), 'pd2': (1.125, 82.4)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112149 is out of bounds for axis 0 with size 68161

Fitting ERROR at  17-56-41 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('17-56-41', '17-57-25')
{'pd1': (1.85, 84.0), 'pd2': (1.125, 80.8)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112165 is out of bounds for axis 0 with size 68161

Fitting ERROR at  17-58-10 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('17-58-10', '17-58-54')
{'pd1': (1.85, 84.0), 'pd2': (1.125, 86.4)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112171 is out of bounds for axis 0 with size 68169

Fitting ERROR at  17-59-38 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('17-59-38', '18-00-22')
{'pd1': (1.85, 84.0), 'pd2': (1.125, 85.6)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112205 is out of bounds for axis 0 with size 68161

Fitting ERROR at  18-01-06 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('18-01-06', '18-01-50')
{'pd1': (1.85, 84.0), 'pd2': (1.125, 80.0)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112187 is out of bounds for axis 0 with size 68163

Fitting ERROR at  18-02-39 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('18-02-39', '18-03-31')
{'pd1': (1.85, 84.0), 'pd2': (1.125, 84.0)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112138 is out of bounds for axis 0 with size 68183

Fitting ERROR at  18-04-24 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('18-04-24', '18-05-17')
{'pd1': (1.85, 84.0), 'pd2': (1.125, 81.6)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112174 is out of bounds for axis 0 with size 68175

Fitting ERROR at  18-06-11 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('18-06-11', '18-07-04')
{'pd1': (1.85, 84.0), 'pd2': (1.125, 83.2)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112173 is out of bounds for axis 0 with size 68183

Fitting ERROR at  18-07-59 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('18-07-59', '18-08-51')
{'pd1': (1.85, 84.0), 'pd2': (1.125, 88.0)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112098 is out of bounds for axis 0 with size 68171

Fitting ERROR at  18-09-42 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('18-09-42', '18-10-35')
{'pd1': (1.85, 84.0), 'pd2': (1.125, 87.2)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112136 is out of bounds for axis 0 with size 68181

Fitting ERROR at  18-11-29 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('18-11-29', '18-12-22')
{'pd1': (1.85, 84.0), 'pd2': (1.125, 84.8)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112126 is out of bounds for axis 0 with size 68173

Fitting ERROR at  18-13-17 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('18-13-17', '18-14-10')
{'pd1': (1.85, 84.0), 'pd2': (0.6900000000000001, 82.4)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112205 is out of bounds for axis 0 with size 68177

Fitting ERROR at  18-15-02 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('18-15-02', '18-15-55')
{'pd1': (1.85, 84.0), 'pd2': (0.6900000000000001, 80.8)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112192 is out of bounds for axis 0 with size 68175

Fitting ERROR at  18-16-49 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('18-16-49', '18-17-41')
{'pd1': (1.85, 84.0), 'pd2': (0.6900000000000001, 86.4)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112084 is out of bounds for axis 0 with size 68167

Fitting ERROR at  18-18-33 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('18-18-33', '18-19-25')
{'pd1': (1.85, 84.0), 'pd2': (0.6900000000000001, 85.6)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112177 is out of bounds for axis 0 with size 68173

Fitting ERROR at  18-20-18 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('18-20-18', '18-21-10')
{'pd1': (1.85, 84.0), 'pd2': (0.6900000000000001, 80.0)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112103 is out of bounds for axis 0 with size 68177

Fitting ERROR at  18-22-04 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('18-22-04', '18-22-56')
{'pd1': (1.85, 84.0), 'pd2': (0.6900000000000001, 84.0)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112145 is out of bounds for axis 0 with size 68183

Fitting ERROR at  18-23-50 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('18-23-50', '18-24-46')
{'pd1': (1.85, 84.0), 'pd2': (0.6900000000000001, 81.6)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112160 is out of bounds for axis 0 with size 68171

Fitting ERROR at  18-25-41 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('18-25-41', '18-26-35')
{'pd1': (1.85, 84.0), 'pd2': (0.6900000000000001, 83.2)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112190 is out of bounds for axis 0 with size 68183

Fitting ERROR at  18-27-30 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('18-27-30', '18-28-23')
{'pd1': (1.85, 84.0), 'pd2': (0.6900000000000001, 88.0)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112110 is out of bounds for axis 0 with size 68175

Fitting ERROR at  18-29-14 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('18-29-14', '18-30-07')
{'pd1': (1.85, 84.0), 'pd2': (0.6900000000000001, 87.2)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112140 is out of bounds for axis 0 with size 68175

Fitting ERROR at  18-30-58 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('18-30-58', '18-31-50')
{'pd1': (1.85, 84.0), 'pd2': (0.6900000000000001, 84.8)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112149 is out of bounds for axis 0 with size 68169

Fitting ERROR at  18-32-43 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('18-32-43', '18-33-33')
{'pd1': (1.85, 84.0), 'pd2': (1.705, 82.4)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112198 is out of bounds for axis 0 with size 68161

Fitting ERROR at  18-34-17 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('18-34-17', '18-35-01')
{'pd1': (1.85, 84.0), 'pd2': (1.705, 80.8)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112141 is out of bounds for axis 0 with size 68161

Fitting ERROR at  18-35-45 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('18-35-45', '18-36-37')
{'pd1': (1.85, 84.0), 'pd2': (1.705, 86.4)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112206 is out of bounds for axis 0 with size 68169

Fitting ERROR at  18-37-28 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('18-37-28', '18-38-22')
{'pd1': (1.85, 84.0), 'pd2': (1.705, 85.6)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112134 is out of bounds for axis 0 with size 68171

Fitting ERROR at  18-39-14 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('18-39-14', '18-40-07')
{'pd1': (1.85, 84.0), 'pd2': (1.705, 80.0)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112207 is out of bounds for axis 0 with size 68187

Fitting ERROR at  18-41-02 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('18-41-02', '18-41-55')
{'pd1': (1.85, 84.0), 'pd2': (1.705, 84.0)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112086 is out of bounds for axis 0 with size 68181

Fitting ERROR at  18-42-50 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('18-42-50', '18-43-45')
{'pd1': (1.85, 84.0), 'pd2': (1.705, 81.6)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112204 is out of bounds for axis 0 with size 68187

Fitting ERROR at  18-44-38 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('18-44-38', '18-45-32')
{'pd1': (1.85, 84.0), 'pd2': (1.705, 83.2)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112138 is out of bounds for axis 0 with size 68169

Fitting ERROR at  18-46-25 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('18-46-25', '18-47-18')
{'pd1': (1.85, 84.0), 'pd2': (1.705, 88.0)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112126 is out of bounds for axis 0 with size 68187

Fitting ERROR at  18-48-12 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('18-48-12', '18-49-06')
{'pd1': (1.85, 84.0), 'pd2': (1.705, 87.2)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112147 is out of bounds for axis 0 with size 68181

Fitting ERROR at  18-50-01 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('18-50-01', '18-50-54')
{'pd1': (1.85, 84.0), 'pd2': (1.705, 84.8)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112133 is out of bounds for axis 0 with size 68169

Fitting ERROR at  18-51-46 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('18-51-46', '18-52-38')
{'pd1': (1.85, 84.0), 'pd2': (0.4, 82.4)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112171 is out of bounds for axis 0 with size 68171

Fitting ERROR at  18-53-31 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('18-53-31', '18-54-26')
{'pd1': (1.85, 84.0), 'pd2': (0.4, 80.8)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112112 is out of bounds for axis 0 with size 68183

Fitting ERROR at  18-55-20 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('18-55-20', '18-56-14')
{'pd1': (1.85, 84.0), 'pd2': (0.4, 86.4)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112187 is out of bounds for axis 0 with size 68185

Fitting ERROR at  18-57-09 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('18-57-09', '18-58-04')
{'pd1': (1.85, 84.0), 'pd2': (0.4, 85.6)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112092 is out of bounds for axis 0 with size 68175

Fitting ERROR at  18-58-58 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('18-58-58', '18-59-53')
{'pd1': (1.85, 84.0), 'pd2': (0.4, 80.0)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112143 is out of bounds for axis 0 with size 68175

Fitting ERROR at  19-00-50 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('19-00-50', '19-01-45')
{'pd1': (1.85, 84.0), 'pd2': (0.4, 84.0)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112093 is out of bounds for axis 0 with size 68171

Fitting ERROR at  19-02-37 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('19-02-37', '19-03-30')
{'pd1': (1.85, 84.0), 'pd2': (0.4, 81.6)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112099 is out of bounds for axis 0 with size 68169

Fitting ERROR at  19-04-25 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('19-04-25', '19-05-18')
{'pd1': (1.85, 84.0), 'pd2': (0.4, 83.2)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112171 is out of bounds for axis 0 with size 68167

Fitting ERROR at  19-06-09 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('19-06-09', '19-07-03')
{'pd1': (1.85, 84.0), 'pd2': (0.4, 88.0)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112160 is out of bounds for axis 0 with size 68171

Fitting ERROR at  19-07-58 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('19-07-58', '19-08-50')
{'pd1': (1.85, 84.0), 'pd2': (0.4, 87.2)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112133 is out of bounds for axis 0 with size 68177

Fitting ERROR at  19-09-45 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('19-09-45', '19-10-40')
{'pd1': (1.85, 84.0), 'pd2': (0.4, 84.8)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112187 is out of bounds for axis 0 with size 68173

Fitting ERROR at  19-11-33 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('19-11-33', '19-12-26')
{'pd1': (1.85, 84.0), 'pd2': (0.9800000000000001, 82.4)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112114 is out of bounds for axis 0 with size 68171

Fitting ERROR at  19-13-21 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('19-13-21', '19-14-14')
{'pd1': (1.85, 84.0), 'pd2': (0.9800000000000001, 80.8)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112131 is out of bounds for axis 0 with size 68167

Fitting ERROR at  19-15-07 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('19-15-07', '19-15-58')
{'pd1': (1.85, 84.0), 'pd2': (0.9800000000000001, 86.4)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112105 is out of bounds for axis 0 with size 68177

Fitting ERROR at  19-16-53 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('19-16-53', '19-17-45')
{'pd1': (1.85, 84.0), 'pd2': (0.9800000000000001, 85.6)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112155 is out of bounds for axis 0 with size 68173

Fitting ERROR at  19-18-39 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('19-18-39', '19-19-32')
{'pd1': (1.85, 84.0), 'pd2': (0.9800000000000001, 80.0)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112146 is out of bounds for axis 0 with size 68177

Fitting ERROR at  19-20-25 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('19-20-25', '19-21-18')
{'pd1': (1.85, 84.0), 'pd2': (0.9800000000000001, 84.0)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112179 is out of bounds for axis 0 with size 68177

Fitting ERROR at  19-22-11 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('19-22-11', '19-23-06')
{'pd1': (1.85, 84.0), 'pd2': (0.9800000000000001, 81.6)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112104 is out of bounds for axis 0 with size 68169

Fitting ERROR at  19-23-58 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('19-23-58', '19-24-50')
{'pd1': (1.85, 84.0), 'pd2': (0.9800000000000001, 83.2)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112115 is out of bounds for axis 0 with size 68169

Fitting ERROR at  19-25-42 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('19-25-42', '19-26-32')
{'pd1': (1.85, 84.0), 'pd2': (0.9800000000000001, 88.0)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112189 is out of bounds for axis 0 with size 68185

Fitting ERROR at  19-27-24 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('19-27-24', '19-28-17')
{'pd1': (1.85, 84.0), 'pd2': (0.9800000000000001, 87.2)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112102 is out of bounds for axis 0 with size 68167

Fitting ERROR at  19-29-10 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('19-29-10', '19-30-04')
{'pd1': (1.85, 84.0), 'pd2': (0.9800000000000001, 84.8)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112128 is out of bounds for axis 0 with size 68169

Fitting ERROR at  19-30-56 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('19-30-56', '19-31-49')
{'pd1': (1.85, 84.0), 'pd2': (0.8350000000000001, 82.4)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112201 is out of bounds for axis 0 with size 68167

Fitting ERROR at  19-32-43 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('19-32-43', '19-33-39')
{'pd1': (1.85, 84.0), 'pd2': (0.8350000000000001, 80.8)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112179 is out of bounds for axis 0 with size 68177

Fitting ERROR at  19-34-31 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('19-34-31', '19-35-25')
{'pd1': (1.85, 84.0), 'pd2': (0.8350000000000001, 86.4)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112104 is out of bounds for axis 0 with size 68181

Fitting ERROR at  19-36-19 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('19-36-19', '19-37-13')
{'pd1': (1.85, 84.0), 'pd2': (0.8350000000000001, 85.6)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112163 is out of bounds for axis 0 with size 68179

Fitting ERROR at  19-38-05 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('19-38-05', '19-38-59')
{'pd1': (1.85, 84.0), 'pd2': (0.8350000000000001, 80.0)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112171 is out of bounds for axis 0 with size 68169

Fitting ERROR at  19-39-54 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('19-39-54', '19-40-47')
{'pd1': (1.85, 84.0), 'pd2': (0.8350000000000001, 84.0)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112140 is out of bounds for axis 0 with size 68177

Fitting ERROR at  19-41-43 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('19-41-43', '19-42-38')
{'pd1': (1.85, 84.0), 'pd2': (0.8350000000000001, 81.6)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112175 is out of bounds for axis 0 with size 68183

Fitting ERROR at  19-43-34 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('19-43-34', '19-44-27')
{'pd1': (1.85, 84.0), 'pd2': (0.8350000000000001, 83.2)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112091 is out of bounds for axis 0 with size 68175

Fitting ERROR at  19-45-18 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('19-45-18', '19-46-12')
{'pd1': (1.85, 84.0), 'pd2': (0.8350000000000001, 88.0)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112125 is out of bounds for axis 0 with size 68177

Fitting ERROR at  19-47-08 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('19-47-08', '19-48-02')
{'pd1': (1.85, 84.0), 'pd2': (0.8350000000000001, 87.2)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112091 is out of bounds for axis 0 with size 68169

Fitting ERROR at  19-48-55 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('19-48-55', '19-49-51')
{'pd1': (1.85, 84.0), 'pd2': (0.8350000000000001, 84.8)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112201 is out of bounds for axis 0 with size 68173

Fitting ERROR at  19-50-43 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('19-50-43', '19-51-37')
{'pd1': (1.85, 84.0), 'pd2': (1.415, 82.4)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112184 is out of bounds for axis 0 with size 68179

Fitting ERROR at  19-52-32 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('19-52-32', '19-53-26')
{'pd1': (1.85, 84.0), 'pd2': (1.415, 80.8)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112205 is out of bounds for axis 0 with size 68165

Fitting ERROR at  19-54-20 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('19-54-20', '19-55-13')
{'pd1': (1.85, 84.0), 'pd2': (1.415, 86.4)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112160 is out of bounds for axis 0 with size 68181

Fitting ERROR at  19-56-07 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('19-56-07', '19-57-02')
{'pd1': (1.85, 84.0), 'pd2': (1.415, 85.6)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112174 is out of bounds for axis 0 with size 68177

Fitting ERROR at  19-57-56 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('19-57-56', '19-58-49')
{'pd1': (1.85, 84.0), 'pd2': (1.415, 80.0)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112151 is out of bounds for axis 0 with size 68175

Fitting ERROR at  19-59-43 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('19-59-43', '20-00-35')
{'pd1': (1.85, 84.0), 'pd2': (1.415, 84.0)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112212 is out of bounds for axis 0 with size 68179

Fitting ERROR at  20-01-27 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-01-27', '20-02-23')
{'pd1': (1.85, 84.0), 'pd2': (1.415, 81.6)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112141 is out of bounds for axis 0 with size 68177

Fitting ERROR at  20-03-16 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-03-16', '20-04-08')
{'pd1': (1.85, 84.0), 'pd2': (1.415, 83.2)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112178 is out of bounds for axis 0 with size 68163

Fitting ERROR at  20-05-01 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-05-01', '20-05-44')
{'pd1': (1.85, 84.0), 'pd2': (1.415, 88.0)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112162 is out of bounds for axis 0 with size 68163

Fitting ERROR at  20-06-28 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-06-28', '20-07-12')
{'pd1': (1.85, 84.0), 'pd2': (1.415, 87.2)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112196 is out of bounds for axis 0 with size 68161

Fitting ERROR at  20-07-55 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-07-55', '20-08-39')
{'pd1': (1.85, 84.0), 'pd2': (1.415, 84.8)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112138 is out of bounds for axis 0 with size 68161

Fitting ERROR at  20-09-22 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-09-22', '20-10-06')
{'pd1': (1.85, 84.0), 'pd2': (0.545, 82.4)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112186 is out of bounds for axis 0 with size 68161

Fitting ERROR at  20-10-49 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-10-49', '20-11-33')
{'pd1': (1.85, 84.0), 'pd2': (0.545, 80.8)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112105 is out of bounds for axis 0 with size 68161

Fitting ERROR at  20-12-17 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-12-17', '20-13-01')
{'pd1': (1.85, 84.0), 'pd2': (0.545, 86.4)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112196 is out of bounds for axis 0 with size 68161

Fitting ERROR at  20-13-44 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-13-44', '20-14-28')
{'pd1': (1.85, 84.0), 'pd2': (0.545, 85.6)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112123 is out of bounds for axis 0 with size 68159

Fitting ERROR at  20-15-12 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-15-12', '20-15-55')
{'pd1': (1.85, 84.0), 'pd2': (0.545, 80.0)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112131 is out of bounds for axis 0 with size 68163

Fitting ERROR at  20-16-39 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-16-39', '20-17-24')
{'pd1': (1.85, 84.0), 'pd2': (0.545, 84.0)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112139 is out of bounds for axis 0 with size 68163

Fitting ERROR at  20-18-07 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-18-07', '20-18-51')
{'pd1': (1.85, 84.0), 'pd2': (0.545, 81.6)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112090 is out of bounds for axis 0 with size 68173

Fitting ERROR at  20-19-35 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-19-35', '20-20-19')
{'pd1': (1.85, 84.0), 'pd2': (0.545, 83.2)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112122 is out of bounds for axis 0 with size 68167

Fitting ERROR at  20-21-02 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-21-02', '20-21-47')
{'pd1': (1.85, 84.0), 'pd2': (0.545, 88.0)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112152 is out of bounds for axis 0 with size 68227

Fitting ERROR at  20-22-32 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-22-32', '20-23-18')
{'pd1': (1.85, 84.0), 'pd2': (0.545, 87.2)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112153 is out of bounds for axis 0 with size 68167

Fitting ERROR at  20-24-04 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-24-04', '20-24-50')
{'pd1': (1.85, 84.0), 'pd2': (0.545, 84.8)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112189 is out of bounds for axis 0 with size 68161

Fitting ERROR at  20-25-34 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-25-34', '20-26-20')
{'pd1': (1.85, 84.0), 'pd2': (1.27, 82.4)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112179 is out of bounds for axis 0 with size 68163

Fitting ERROR at  20-27-05 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-27-05', '20-27-51')
{'pd1': (1.85, 84.0), 'pd2': (1.27, 80.8)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112093 is out of bounds for axis 0 with size 68161

Fitting ERROR at  20-28-39 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-28-39', '20-29-29')
{'pd1': (1.85, 84.0), 'pd2': (1.27, 86.4)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112134 is out of bounds for axis 0 with size 68193

Fitting ERROR at  20-30-22 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-30-22', '20-31-20')
{'pd1': (1.85, 84.0), 'pd2': (1.27, 85.6)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112213 is out of bounds for axis 0 with size 68183

Fitting ERROR at  20-32-12 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-32-12', '20-33-07')
{'pd1': (1.85, 84.0), 'pd2': (1.27, 80.0)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112176 is out of bounds for axis 0 with size 68171

Fitting ERROR at  20-33-57 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-33-57', '20-34-48')
{'pd1': (1.85, 84.0), 'pd2': (1.27, 84.0)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112112 is out of bounds for axis 0 with size 68173

Fitting ERROR at  20-35-41 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-35-41', '20-36-35')
{'pd1': (1.85, 84.0), 'pd2': (1.27, 81.6)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112186 is out of bounds for axis 0 with size 68179

Fitting ERROR at  20-37-26 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-37-26', '20-38-18')
{'pd1': (1.85, 84.0), 'pd2': (1.27, 83.2)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112117 is out of bounds for axis 0 with size 68169

Fitting ERROR at  20-39-08 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-39-08', '20-39-58')
{'pd1': (1.85, 84.0), 'pd2': (1.27, 88.0)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112191 is out of bounds for axis 0 with size 68171

Fitting ERROR at  20-40-50 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-40-50', '20-41-42')
{'pd1': (1.85, 84.0), 'pd2': (1.27, 87.2)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112123 is out of bounds for axis 0 with size 68169

Fitting ERROR at  20-42-28 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-42-28', '20-43-15')
{'pd1': (1.85, 84.0), 'pd2': (1.27, 84.8)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112133 is out of bounds for axis 0 with size 68161

Fitting ERROR at  20-44-02 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-44-02', '20-44-50')
{'pd1': (1.85, 84.0), 'pd2': (1.56, 82.4)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112104 is out of bounds for axis 0 with size 68169

Fitting ERROR at  20-45-40 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-45-40', '20-46-29')
{'pd1': (1.85, 84.0), 'pd2': (1.56, 80.8)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112102 is out of bounds for axis 0 with size 68169

Fitting ERROR at  20-47-19 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-47-19', '20-48-09')
{'pd1': (1.85, 84.0), 'pd2': (1.56, 86.4)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112204 is out of bounds for axis 0 with size 68169

Fitting ERROR at  20-49-00 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-49-00', '20-49-52')
{'pd1': (1.85, 84.0), 'pd2': (1.56, 85.6)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112149 is out of bounds for axis 0 with size 68169

Fitting ERROR at  20-50-43 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-50-43', '20-51-33')
{'pd1': (1.85, 84.0), 'pd2': (1.56, 80.0)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112126 is out of bounds for axis 0 with size 68163

Fitting ERROR at  20-52-23 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-52-23', '20-53-13')
{'pd1': (1.85, 84.0), 'pd2': (1.56, 84.0)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112148 is out of bounds for axis 0 with size 68177

Fitting ERROR at  20-54-03 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-54-03', '20-54-56')
{'pd1': (1.85, 84.0), 'pd2': (1.56, 81.6)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112096 is out of bounds for axis 0 with size 68171

Fitting ERROR at  20-55-47 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-55-47', '20-56-40')
{'pd1': (1.85, 84.0), 'pd2': (1.56, 83.2)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112101 is out of bounds for axis 0 with size 68175

Fitting ERROR at  20-57-31 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-57-31', '20-58-23')
{'pd1': (1.85, 84.0), 'pd2': (1.56, 88.0)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112170 is out of bounds for axis 0 with size 68167

Fitting ERROR at  20-59-12 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('20-59-12', '20-59-57')
{'pd1': (1.85, 84.0), 'pd2': (1.56, 87.2)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112155 is out of bounds for axis 0 with size 68163

Fitting ERROR at  21-00-42 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('21-00-42', '21-01-27')
{'pd1': (1.85, 84.0), 'pd2': (1.56, 84.8)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112124 is out of bounds for axis 0 with size 68161

Fitting ERROR at  21-02-12 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('21-02-12', '21-02-56')
{'pd1': (1.85, 84.0), 'pd2': (1.85, 82.4)}
Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 549, in _load_single_run_rel_scat
    dh1.setAllCAT(0.002)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 759, in setAllCAT
    self.setBaseline(timeBuffer)
  File "c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py", line 301, in setBaseline
    if (self.voltage[i] > 6*0.01):
        ~~~~~~~~~~~~^^^
IndexError: index 112137 is out of bounds for axis 0 with size 68161

Fitting ERROR at  21-03-41 

Traceback (most recent call last):
  File "<ipython-input-44-c8e8e635bf4e>", line 491, in get_rel_scattering_df
    fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 515, in get_rel_scattering
    resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-44-c8e8e635bf4e>", line 576, in _load_single_run_rel_scat
    scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
                 ~~~~~~~~~~~^^^^^^^^^
KeyError: 'motSS'

Error 'motSS' at ('21-03-41', '21-04-25')
{'pd1': (1.85, 84.0), 'pd2': (1.85, 80.8)}
---------------------------------------------------------------------------
KeyboardInterrupt                         Traceback (most recent call last)
Cell In[45], line 1
----> 1 get_rel_scattering_df(r'C:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\CATMeasurements\relScatRate\TrapDepthMap')

Cell In[44], line 491, in get_rel_scattering_df(data_folder)
    488 					#print(f.readlines())
    490 				timestamp = get_timestamp(run_path)
--> 491 				fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
    493 				extracted_values = {
    494 						'pa1': result['pd1'][0],
    495 						'pd1': result['pd1'][1],
   (...)
    499       					'timestamp': timestamp
    500 					}
    501 				depth_ratios_df.append(extracted_values)

Cell In[44], line 515, in get_rel_scattering(run_path1, run_path2)
    514 def get_rel_scattering(run_path1, run_path2):
--> 515 	resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
    516 	resultDict2, scat_ratio2 = _load_single_run_rel_scat(run_path2, plot=True)
    518 	print(f"scat_ratio 1, (2 inverted) = {scat_ratio1:.3f}, {1/scat_ratio2:.3f}")

Cell In[44], line 538, in _load_single_run_rel_scat(run_path, plot, cache_all)
    536 try: 
    537 	dh1 = MTdataHost(SAMPLE_RATE)
--> 538 	dh1.loadCATdata(fileName=filename, settingsName=settingsname)
    540 	dh1.tBaseline = 1
    541 	dh1.tLoad = 2

File c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py:116, in MTdataHost.loadCATdata(self, fileName, settingsName)
    <a href='file:///c%3A/Users/svars/OneDrive/Desktop/UBC%20Lab/CATExperiment/analysis/MT_class_PID_new.py?line=104'>105</a> '''
    <a href='file:///c%3A/Users/svars/OneDrive/Desktop/UBC%20Lab/CATExperiment/analysis/MT_class_PID_new.py?line=105'>106</a> loads data from a .csv file and setting file as written by CATmeasurement.py
    <a href='file:///c%3A/Users/svars/OneDrive/Desktop/UBC%20Lab/CATExperiment/analysis/MT_class_PID_new.py?line=106'>107</a> 
   (...)
    <a href='file:///c%3A/Users/svars/OneDrive/Desktop/UBC%20Lab/CATExperiment/analysis/MT_class_PID_new.py?line=110'>111</a> settingsName - location of .txt file containing apparatus parameters set during measurement
    <a href='file:///c%3A/Users/svars/OneDrive/Desktop/UBC%20Lab/CATExperiment/analysis/MT_class_PID_new.py?line=111'>112</a> '''
    <a href='file:///c%3A/Users/svars/OneDrive/Desktop/UBC%20Lab/CATExperiment/analysis/MT_class_PID_new.py?line=113'>114</a> self.CATbkBool = False
--> <a href='file:///c%3A/Users/svars/OneDrive/Desktop/UBC%20Lab/CATExperiment/analysis/MT_class_PID_new.py?line=115'>116</a> data = np.genfromtxt(fileName ,dtype=None, comments="#", delimiter=",", skip_header=1)
    <a href='file:///c%3A/Users/svars/OneDrive/Desktop/UBC%20Lab/CATExperiment/analysis/MT_class_PID_new.py?line=116'>117</a> self.settings = eval(open(settingsName, 'r').read())
    <a href='file:///c%3A/Users/svars/OneDrive/Desktop/UBC%20Lab/CATExperiment/analysis/MT_class_PID_new.py?line=118'>119</a> self.timeBaseline = self.settings['wait_baseline']

File c:\ProgramData\Anaconda3\envs\magpy_env\Lib\site-packages\numpy\lib\npyio.py:2226, in genfromtxt(fname, dtype, comments, delimiter, skip_header, skip_footer, converters, missing_values, filling_values, usecols, names, excludelist, deletechars, replace_space, autostrip, case_sensitive, defaultfmt, unpack, usemask, loose, invalid_raise, max_rows, encoding, ndmin, like)
   <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/numpy/lib/npyio.py?line=2222'>2223</a> append_to_invalid = invalid.append
   <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/numpy/lib/npyio.py?line=2224'>2225</a> # Parse each line
-> <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/numpy/lib/npyio.py?line=2225'>2226</a> for (i, line) in enumerate(itertools.chain([first_line, ], fhd)):
   <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/numpy/lib/npyio.py?line=2226'>2227</a>     values = split_line(line)
   <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/numpy/lib/npyio.py?line=2227'>2228</a>     nbvalues = len(values)

File <frozen codecs>:319, in decode(self, input, final)

KeyboardInterrupt: 
In [ ]:
import os
import sys
from functools import partial
sys.path.append(os.path.join(os.getcwd(), '..')) #adds directory below as valid path
from  datetime import datetime, timedelta
dateformat = "%H-%M-%S"
from collections import deque
import traceback
from multiprocessing import Pool
from tqdm import tqdm

import scipy.constants as spc
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd

plt.rcParams['axes.grid'] = True
plt.rcParams['grid.linestyle'] = '--'

from MT_class_PID_new import MTdataHost
from global_folder.myplotsty import *
from global_folder.my_helpers import *

PUMP_FREQUENCY = 384228.6
REPUMP_FREQUENCY = 384228.6 + 6.56
SAMPLE_RATE = 2000
FREQVSVOLT = 221.0 
FREQVSCURR = 1.13

# TODO: find a better place for this
EXP_FOLDER =r'C:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\CATMeasurements'
MEASURE_FOLDER = os.path.join(EXP_FOLDER, 'testPArun16')
WDATA_FOLDER =os.path.join(MEASURE_FOLDER, 'testPArun16.csv')

# TODO: maybe make a run analysis class out of this?
def dump():
	fig, ax = plt.subplots()
	plot_results(ax, df, max_freq= 384219., fmt='o', mfc='red', save_folder=MEASURE_FOLDER)
	plt.savefig(os.path.join(MEASURE_FOLDER, 'ratio_vs_freq.png'))

	
	collect_plots(MEASURE_FOLDER, os.path.join(MEASURE_FOLDER, 'collected_plots'), 'deloadPhase.png')
 
	#*-----------------------
	#* SINGLE RUN
 	#*----------------------- 
  
	MEASURE_FOLDER = os.path.join(EXP_FOLDER, 'testPArun9')
	df = get_data_frame(MEASURE_FOLDER)
	df.dropna(inplace=True)
	#freqs = plot_results(df, 384201., save_folder=MEASURE_FOLDER)
 
	data = df.dropna()
	freqs = ((384201-PUMP_FREQUENCY)-(data['tempV']-df['tempV'].min())*FREQVSVOLT- (data['currV']-df['currV'].min())*FREQVSCURR)
	fig, ax = plt.subplots()
	plot_spline_fit(ax=ax, x=freqs, y=data['ratio'], yerr=data['ratioErr'], 
				 s=0.1, save_folder=MEASURE_FOLDER, 
				 mfc='red', color='black', 
				 title='Trap Depth = 1.99 K')
 
	# *-----------------------
	# * MULTIPLE RUN COMPARISON
 	# *-----------------------
	folders = [os.path.join(EXP_FOLDER, path ) for path in ['testPARun11', 'testPARun12', 'testPARun13', 'testPARun14']]
	dfs = [get_data_frame(measure_folder, cache_all=True) for measure_folder in folders]

	colors = ['red', 'dodgerblue', 'green', 'grey']
	max_freqs = [384178.881, 384178.593,384179.068, 384184.731]
	#max_freqs=[384178.599, 384179.091, 384184.733]

	zipped_data = list(zip(dfs, max_freqs))
	fig, ax = plt.subplots()
	for i, (df, max_freq)  in enumerate(zipped_data[:3]):
		data = df.dropna()
		freqs = ((max_freq-PUMP_FREQUENCY)-(data['tempV']-data['tempV'].min())*FREQVSVOLT- (data['currV']-data['currV'].min())*FREQVSCURR)
		color = colors[i]
		ax=plot_spline_fit(ax, x=freqs, y=data['ratio'], scolor=color, mfc=color,color=color, s=0.02, ms=5)

	#*-----------------------
	#* PARSING WAVEMETER DATA
 	#*-----------------------

	MEASURE_FOLDER = os.path.join(EXP_FOLDER, 'testPArun14')
	WDATA_FOLDER =os.path.join(MEASURE_FOLDER, 'testPArun14.csv')
	freq_data, max_freq, min_freq = add_wavemeter_data('', WDATA_FOLDER)
	data = freq_data[:]
	levels = staircase_fit(data)

	data = get_data_frame(MEASURE_FOLDER)
	data.dropna(inplace=True)
	freqs = ((max_freq)-(data['tempV']-data['tempV'].min())*FREQVSVOLT- (data['currV']-data['currV'].min())*FREQVSCURR)
	plt.plot(freqs)
 
	#*-----------------------
	#* GETTING DEPTH_RATIO DATAFRAME
 	#*-----------------------
	MEASURE_FOLDER = r'C:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\CATMeasurements\relScatRate'
	depth_ratios_df = get_rel_scattering_df(MEASURE_FOLDER)
	df_slice = depth_ratios_df[(depth_ratios_df['pa1']==1.85) & (depth_ratios_df['pd1']==84) & (depth_ratios_df['pd2'] == 84)]
	x = df_slice['pa2']
	y = df_slice['depth_ratio']
	plt.plot(x,y, 'o')

	#*-----------------------
	#* MEGA_RUN
 	#*-----------------------	
	MEASURE_FOLDER = os.path.join(EXP_FOLDER, 'testPARunMega')
	df = get_data_frame(MEASURE_FOLDER)
	df.dropna(inplace=True)

	df_grouped = df.groupby(by='pump_reference')
	min_ratios = df_grouped['ratio'].min()

	groups = dict(list(df_grouped))
	dfs = [df for df in groups.values()]
 
	max_freqs = [384182.5]*15
	#max_freqs=[384178.599, 384179.091, 384184.733]
	zipped_data = list(zip(dfs, max_freqs))
	fig, ax = plt.subplots()
	for i, (df, max_freq)  in enumerate(zipped_data[:]):
		data = df.dropna()
		freqs = ((max_freq-PUMP_FREQUENCY)-(data['tempV']-data['tempV'].min())*FREQVSVOLT- (data['currV']-data['currV'].min())*FREQVSCURR)
		ax=plot_spline_fit(ax, x=freqs, y=data['ratio'], yerr=data['ratioErr'],scolor=f'C{i}', mfc=f'C{i}',color=f'C{i}', s=0.0, ms=5, figsize=(10, 10), label=f"Pump Amplituide = { df.iloc[10]['pump_reference'] :.2f}", linewidth=2.5)

	plt.legend()

	plt.savefig(os.path.join(MEASURE_FOLDER, 'lossFeatures.png'))
	#*-----------------------
	#* MULTIPLE MEGARUN
	#*-----------------------
 
	folders = [os.path.join(EXP_FOLDER, path ) for path in ['testPArunMega', 'testPArunMega2']]
	dfs_mega = [get_data_frame(measure_folder, cache_all=True).dropna() for measure_folder in folders]

	dfs_grouped = [df_mega.groupby(by='pump_reference') for df_mega in dfs_mega]
	min_ratios = [df_grouped['ratio'].min() for df_grouped in dfs_grouped]

	groupss = [dict(list(df_grouped)) for df_grouped in dfs_grouped]
	dfs = [ [df for df in groups.values()] for groups in groupss]
 
	for row in dfs:
		x = [df['pump_reference'].mean() for df in row]
		y = [(df['ratio'].max() - df['ratio'].min())/df['motSS'].std() for df in row]
		plt.plot( x, y ,'-o', label=fr"$\delta$ = {180 - 2*row[0]['pump_AOM_freq'].mean()} MHz")
		plt.xlabel('Pump Amplitude')
		plt.ylabel(r'SNR $ = \frac{V_{ss, off} - V_{ss, on}}{\sigma_{V,off}}$ ')
	plt.legend()

def freq_misc():
	WDATA_FOLDER = r'C:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\CATMeasurements\CATcurrTestrun3.csv'
	freq_data = add_wavemeter_data('', WDATA_FOLDER)
	levels = staircase_fit(freq_data[0], peak_height=0.2, distance=50, data_offset=1, window_size=1) 

	plt.close()
 
	x = np.linspace(0, 4.9, 25)
	y = levels
 
	plt.plot(levels, '-o')
	plt.title('Levels plot')
	
	m, b, fit_line = my_linear_fit(x, y)
def save_fit_results(run_path, plot=False):
	filename = os.path.join(run_path, 'data.csv')
	bkfilename = os.path.join(run_path, 'data_oldPD.csv')
	settingsname = os.path.join(run_path, 'Settings.txt')
	
	dataHost = MTdataHost(SAMPLE_RATE)
	dataHost.loadCATdata(fileName=filename, settingsName=settingsname)
	dataHost.CATbackgroundData(bkfilename)
	
	dataHost.setAllCAT(0.002)
	resultDict = dataHost.getResults(run_path, store=True)
 
	if plot:
		dataHost.storeFits(run_path, combined=True, separate=True)
  
	return resultDict, dataHost.settings
		
def get_timestamp(run_path):
	timestamp = datetime.strptime(os.path.split(run_path)[-1].split('_')[0], dateformat)
	return timestamp

def extract_fit(run_path, plot=True, cache_failed=True, cache_all=True):
	"""Gather relevant data from each measurement run

	Args:
		run_path : absolute path to the run directory
		plot (bool, optional): plot fits. Defaults to True.
		cache_failed (bool, optional): Cache failed fits. If false, refit. Doesn't refit non-failed fits. Defaults to True.
		cache_all (bool, optional): If false, ignore any cached fit_results. Defaults to True.

	Returns:
		a 3-tuple (fit_results, settings, timestamp)
	"""
	fit_results, settings, timestamp = {}, {}, None
	
	if not os.path.isdir(run_path):
		return fit_results, settings, timestamp  # directory is not a run directory

	try:
		timestamp = get_timestamp(run_path)
  
  	# TODO: specify which error to catch
	except Exception as e:
		print("Error extracting timestamp from: ", run_path)
		print(traceback.format_exc())
	
	MAT_fit_cache_path = os.path.join(run_path, 'resultDict.txt')
 
	if not os.path.exists(MAT_fit_cache_path) or not cache_all:
		
		try: 
			fit_results, settings = save_fit_results(run_path, plot=plot)
		except Exception as e:
			print(traceback.format_exc())
			print("Fitting ERROR at ", os.path.basename(run_path), '\n')

			with open(MAT_fit_cache_path, 'w') as f:
				f.write(str('MAT fit failed'))
		
	else:
		print("Accessing cached results from :", os.path.basename(run_path))
  
		fit_results = open(MAT_fit_cache_path, 'r').read()

		if fit_results == 'MAT fit failed':
			if not cache_failed:
				# fit regardless of cached result
				try: 
					fit_results, settings = save_fit_results(run_path, plot=plot)
				except Exception as e:
					print(traceback.format_exc())
					print("Fitting ERROR at ", os.path.basename(run_path), '\n')
	
					with open(MAT_fit_cache_path, 'w') as f:
						f.write(str('MAT fit failed'))	
			else:
				print("Failed fit at :", os.path.basename(run_path))
				fit_results = {}

		else:
			fit_results = eval(open(MAT_fit_cache_path, 'r').read())
   
			settingsname = os.path.join(run_path, 'Settings.txt')
			settings = eval(open(settingsname, 'r').read())
   
	return fit_results, settings, timestamp



def get_row(run_path, **kwargs):
			
   fit_results, settings, timestamp = extract_fit(run_path, **kwargs)
   row = {**fit_results, **settings, **{'timestamp':timestamp}}
   
   return row

   
def get_data_frame(data_dir, parallel=True, in_process_run=False, **kwargs):
   
	run_path_arr = []
	rows = []
	
	for relative_path in os.listdir(data_dir):
		run_path_arr.append(os.path.join(data_dir, relative_path))
  
	if in_process_run:
		run_path_arr.pop()

	run_path_arr = sorted(run_path_arr)
	
	if parallel:
		with Pool(4) as p:
			rows = list(tqdm(p.imap(partial(get_row, **kwargs), run_path_arr), total=len(run_path_arr)))
	
	else:
		for run_path in tqdm(run_path_arr):
		   rows.append(get_row(run_path, **kwargs))

	return pd.DataFrame.from_dict(rows)

def add_wavemeter_data(df, wmeter_csv_path, window_size=100, num_rows=50):


	"""Extract unique frequnecy values from wavemeter data
	Returns:
		unique_levels (list): unique frequency values in wavemeter data
	"""
 
	# TODO: modify dataframe in place with frequency data
 
	wdata = pd.read_csv(wmeter_csv_path, skiprows=2)
	wdata.dropna(inplace=True)
	freq_data = np.array(wdata.iloc[:, 0])
	try:
		freq_data = np.array([float(item) for item in freq_data if item.replace('.','').isdigit()])
	except Exception as e:
		print(e)
 
	max_freq = freq_data.max()
	min_freq = freq_data.min()

	return freq_data, max_freq, min_freq

def plot_results(ax, dfs, max_freq, min_freq=0.0, mfc='red', fmt='o', ms=5, save_folder=False, xscale=1.0, yscale=1.0, **kwargs):
	FREQVSVOLT = 221.0 
	FREQVSCURR = 1.13
	
	if not type(dfs) == list:
		freqs = ((max_freq-PUMP_FREQUENCY)-(dfs.dropna()['tempV']-dfs.dropna()['tempV'].min())*FREQVSVOLT- (dfs.dropna()['currV']-dfs.dropna()['currV'].min())*FREQVSCURR)*xscale
		dfs=[dfs]
  
	plt.gcf().set_dpi(300)
	
	for df in dfs:
		df = df.dropna()
		ax.errorbar(freqs, 
			   df['ratio']*yscale,
			   yerr=df['ratioErr'],
			   fmt=fmt, mfc=mfc, color='black', ms=ms, **kwargs)
		ax.set_ylabel(r'$\mathbf{\frac{V_{ss, cat}}{V_{ss}}} $ ', **labeldict)
		ax.set_xlabel(r'$\Delta $ (GHz)', **labeldict)
	
	if save_folder:
		plt.savefig(os.path.join(save_folder, 'ratio_vs_freq.png'))
	
	return freqs, ax
  
	#return plt.gca(), plt.gcf()
	#plt.show()

def plot_spline_fit(ax, x, y, s=1, yerr=None, color='black', scolor='black',figsize=(12,5), save_folder=None, title='',alpha=0.5,dpi=200, label='plot',**kwargs):
	from scipy.interpolate import splev, splrep
	xnew = np.linspace(min(x), max(x), 3*len(x) )

	y = [b for a,b in sorted(zip(x,y), key=lambda pair: pair[0])]
	if yerr is not None:
		yerr = [b for a,b in sorted(zip(x,yerr), key=lambda pair: pair[0])]
 
	x = sorted(x)

	spl = splrep(x, y, s=s)
	ynew = splev(xnew, spl)

	
	plt.gcf().set_dpi(dpi)
	plt.gcf().set_size_inches(figsize)
	
	if yerr is not None:
		ax.errorbar(x, y, yerr=yerr, fmt='o', **kwargs)
	else:
		ax.plot(x,y, 'o', **kwargs)
	ax.plot(xnew, ynew, '-', color=scolor, alpha=alpha, label=label, **kwargs)
 
	ax.set_ylabel(r'$\mathbf{\frac{V_{ss, cat}}{V_{ss}}} $ ', **labeldict)
	ax.set_xlabel(r'$\Delta $ (GHz)', **labeldict)
 
	ax.set_title(title, **titledict)
	if save_folder:
		plt.savefig(os.path.join(save_folder, 'spline_ratio_vs_freq.png'))
	
	return ax
 
def plot_polyfit(x_data, y_data, spline_degree):
	
	coefficients = np.polyfit(x_data, y_data, spline_degree)

	x_interp = np.linspace(min(x_data), max(x_data), 100)
	y_interp = np.polyval(coefficients, x_interp)

	plt.scatter(x_data, y_data, label='Original Data')
	plt.plot(x_interp, y_interp, label='Polynomial Interpolation (Degree={})'.format(spline_degree))

def collect_plots(source, destination, plot_name):
	print(f'Collecting plots from {os.path.basename(source)}')
	import shutil

	os.makedirs(destination, exist_ok=True)

	plot_files = []
	for root, dirs, files in os.walk(source):
		
		for file in files:
			if file == plot_name:
				plot_files.append(os.path.join(root, file))

	for i, plot_file in enumerate(plot_files, start=0):
		new_filename = f'{i}{plot_name}'
		destination_path = os.path.join(destination, new_filename)
		shutil.copy(plot_file, destination_path)

def create_GIF(images_folder, image_name):
	import imageio
	with imageio.get_writer(os.path.join(images_folder, f'{image_name}movie.gif'), mode='I', duration=0.5) as writer:
		for filename in os.listdir(images_folder):
			if image_name in filename:
				image = imageio.imread(os.path.join(images_folder, filename))
				writer.append_data(image)

def staircase_fit(data, peak_height=0.1, distance=100, data_offset=1, window_size=1, inc_final_peak=True):
	def moving_average(arr, window_size):
		weights = np.ones(window_size) / window_size
		return np.convolve(arr, weights, mode='valid')

	convdata1 = moving_average(data, window_size)
	convdata2 = moving_average(data[data_offset+1:], window_size )
	final = convdata1[:len(convdata2)]-convdata2
	# plt.plot(data)
	# plt.plot(convdata1)
	# plt.plot(convdata2)
	# plt.show()
	# plt.plot(final)

	
	from scipy.signal import find_peaks
	x= final
	peaks, _ = find_peaks(x, height=peak_height, distance=distance)
	peaks = np.insert(peaks, 0, 0)
	levels = []
	plot_arr = []
	for i, peak in enumerate(peaks):
		
		if i < len(peaks) - 1:
			temp = data[ peaks[i]:peaks[i+1] ]
			plot_arr.extend( np.ones_like(temp)*np.mean(temp))
			levels.append(np.mean(temp))
	if inc_final_peak:
		temp = data[peaks[-1]:]
		levels.append(np.mean(temp))
		plot_arr.extend( np.ones_like(temp)*np.mean(temp))
  
	plt.plot(x)
	plt.plot(peaks, x[peaks], "x")
	plt.plot(np.zeros_like(x), "--", color="gray")
	plt.show()
	
	plt.plot(data)
	plt.plot(np.ravel((plot_arr)))
	plt.show()
	plt.close()
	plt.plot(np.array(levels)[np.where(abs(np.diff(levels))>0.05)[0]], 'o', ms=5)
 
	return levels

def load_single_run(run_path):
	filename = os.path.join(run_path, 'data.csv')
	bkfilename = os.path.join(run_path, 'data_oldPD.csv')
	settingsname = os.path.join(run_path, 'Settings.txt')
	
	dh1 = MTdataHost(SAMPLE_RATE)
	dh1.loadCATdata(fileName=filename, settingsName=settingsname)
	
	return dh1
	# *-----------------------
	# *RELATIVE SCATTERING RATE
	# *-----------------------


def get_rel_scattering_df(data_folder):
	depth_ratios_df = []
	listdir = sorted(os.listdir(data_folder))
	try:
		for run_folder1, run_folder2 in [listdir[i:i+2] for i in range(len(listdir))[::2]]:
			try:
				run_path1 = os.path.join(data_folder, run_folder1)
				run_path2 = os.path.join(data_folder, run_folder2)
				result = {}
				with open(os.path.join(run_path1, 'twoSettings.txt'), 'r') as f:
					settings = f.read() 
					import re

					pattern = r'(\w+)\s*=\s*\(([\d.]+),\s*([\d.]+)\)'

					matches = re.findall(pattern, settings)

					
					for match in matches:
						key = match[0]
						value1 = float(match[1])
						value2 = float(match[2])
						result[key] = (value1, value2)

					print(result)
				with open(os.path.join(run_path2, 'twoSettings.txt'), 'r') as f:
					pass
					#print(f.readlines())
				
				timestamp = get_timestamp(run_path)
				fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
				
				extracted_values = {
						'pa1': result['pd1'][0],
						'pd1': result['pd1'][1],
						'pa2': result['pd2'][0],
						'pd2': result['pd2'][1],
						'depth_ratio': 1/float(depth_ratio), # ratio between current and std settings
      					'timestamp': timestamp
					}
				depth_ratios_df.append(extracted_values)
				
				print('\n')
			except Exception as e:
					print(traceback.format_exc())
					print(f'Error {e} at {run_folder1, run_folder2}')
	except Exception as e:
		print(f'Error {e}')

	depth_ratios_df = pd.DataFrame(depth_ratios_df)
 
	return depth_ratios_df

def get_rel_scattering(run_path1, run_path2):
	resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
	resultDict2, scat_ratio2 = _load_single_run_rel_scat(run_path2, plot=True)
	
	print(f"scat_ratio 1, (2 inverted) = {scat_ratio1:.3f}, {1/scat_ratio2:.3f}")
	scat_ratio_avg = (scat_ratio1+1/scat_ratio2)/2
	
	Rratio = resultDict1['initMOTR']/resultDict2['initMOTR']
	print(fr"Rratio = {resultDict1['initMOTR']:.3f} / {resultDict2['initMOTR']:.3f} = {Rratio:.3f}")
	depthRatio = np.sqrt(Rratio/scat_ratio_avg)
	
	return resultDict1, resultDict2, depthRatio


def _load_single_run_rel_scat(run_path, plot=False, cache_all=False):
	filename = os.path.join(run_path, 'data.csv')
	settingsname = os.path.join(run_path, 'Settings.txt')
	
	MAT_fit_cache_path = os.path.join(run_path, 'resultDict.txt')
	fit_results = {}
	if not os.path.exists(MAT_fit_cache_path) or not cache_all:
		
		try: 
			dh1 = MTdataHost(SAMPLE_RATE)
			dh1.loadCATdata(fileName=filename, settingsName=settingsname)

			dh1.tBaseline = 1
			dh1.tLoad = 2
			dh1.timeLoad = 30
			dh1.tReload = dh1.tLoad + dh1.timeLoad
			dh1.timeReload = 1
			dh1.tCATbackground = dh1.tReload + dh1.timeReload

			#dh1.setOffset()
			#dh1.setCATtiming()
			dh1.setAllCAT(0.002)

			print('FITTINGGGGGGGGGGGG')
			fit_results = dh1.getResults(run_path, store=True)
			if plot:
				dh1.storeFits(run_path, combined=True, separate=False)
		except Exception as e:
			print(traceback.format_exc())
			print("Fitting ERROR at ", os.path.basename(run_path), '\n')

			with open(MAT_fit_cache_path, 'w') as f:
				f.write(str('MAT fit failed'))
		
	else:
		print("Accessing cached results from :", os.path.basename(run_path))

		fit_results = open(MAT_fit_cache_path, 'r').read()

		if fit_results == 'MAT fit failed':
			print("Failed fit at :", os.path.basename(run_path))
			fit_results = {}

		else:
			fit_results = eval(open(MAT_fit_cache_path, 'r').read())


	
	scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
	fit_results['scat_ratio'] = scat_ratio
 	#scat_ratio = dh1.motSS/(dh1.reloadVolt+dh1.baseVolt - (dh1.CATbackgroundVolt+dh1.noLightBackground))
	
	return fit_results, scat_ratio

def scat_rate(I, delta, gamma=6.065, Is=1.669):
	"""_summary_

	Args:
		I (float): intensity (Mhz)
		delta (float): detuning (Mhz)
		gamma (float, optional): linewidth (Mhz) Defaults to 6.065.
		Is (float, optional): Should be one of 3.576(isotropic), 2.503(pi), 1.669 (sigma+-). Defaults to 1.669.

	Returns:
		_type_: gamma: the scattering rate
	"""
	return gamma*I/(2*Is*(1+I/Is+4*(delta/gamma)**2))

if __name__ == '__main__':
	run_path = r"C:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\CATMeasurements\testPArun9\16-53-10"
	filename = os.path.join(run_path, 'data.csv')
	bkfilename = os.path.join(run_path, 'data_oldPD.csv')
	settingsname = os.path.join(run_path, 'Settings.txt')
	
	dh1 = MTdataHost(SAMPLE_RATE)
	dh1.loadCATdata(fileName=filename, settingsName=settingsname)
	
 	#dh1.CATbackgroundData(bkfilename)
	dh1.setAllCAT(0.002)
In [ ]:
import os
import sys
from functools import partial
sys.path.append(os.path.join(os.getcwd(), '..')) #adds directory below as valid path
from  datetime import datetime, timedelta
dateformat = "%H-%M-%S"
from collections import deque
import traceback
from multiprocessing import Pool
from tqdm import tqdm

import scipy.constants as spc
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd

plt.rcParams['axes.grid'] = True
plt.rcParams['grid.linestyle'] = '--'

from MT_class_PID_new import MTdataHost
from global_folder.myplotsty import *
from global_folder.my_helpers import *

PUMP_FREQUENCY = 384228.6
REPUMP_FREQUENCY = 384228.6 + 6.56
SAMPLE_RATE = 2000
FREQVSVOLT = 221.0 
FREQVSCURR = 1.13

# TODO: find a better place for this
EXP_FOLDER =r'C:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\CATMeasurements'
MEASURE_FOLDER = os.path.join(EXP_FOLDER, 'testPArun16')
WDATA_FOLDER =os.path.join(MEASURE_FOLDER, 'testPArun16.csv')

# TODO: maybe make a run analysis class out of this?
def dump():
	fig, ax = plt.subplots()
	plot_results(ax, df, max_freq= 384219., fmt='o', mfc='red', save_folder=MEASURE_FOLDER)
	plt.savefig(os.path.join(MEASURE_FOLDER, 'ratio_vs_freq.png'))

	
	collect_plots(MEASURE_FOLDER, os.path.join(MEASURE_FOLDER, 'collected_plots'), 'deloadPhase.png')
 
	#*-----------------------
	#* SINGLE RUN
 	#*----------------------- 
  
	MEASURE_FOLDER = os.path.join(EXP_FOLDER, 'testPArun9')
	df = get_data_frame(MEASURE_FOLDER)
	df.dropna(inplace=True)
	#freqs = plot_results(df, 384201., save_folder=MEASURE_FOLDER)
 
	data = df.dropna()
	freqs = ((384201-PUMP_FREQUENCY)-(data['tempV']-df['tempV'].min())*FREQVSVOLT- (data['currV']-df['currV'].min())*FREQVSCURR)
	fig, ax = plt.subplots()
	plot_spline_fit(ax=ax, x=freqs, y=data['ratio'], yerr=data['ratioErr'], 
				 s=0.1, save_folder=MEASURE_FOLDER, 
				 mfc='red', color='black', 
				 title='Trap Depth = 1.99 K')
 
	# *-----------------------
	# * MULTIPLE RUN COMPARISON
 	# *-----------------------
	folders = [os.path.join(EXP_FOLDER, path ) for path in ['testPARun11', 'testPARun12', 'testPARun13', 'testPARun14']]
	dfs = [get_data_frame(measure_folder, cache_all=True) for measure_folder in folders]

	colors = ['red', 'dodgerblue', 'green', 'grey']
	max_freqs = [384178.881, 384178.593,384179.068, 384184.731]
	#max_freqs=[384178.599, 384179.091, 384184.733]

	zipped_data = list(zip(dfs, max_freqs))
	fig, ax = plt.subplots()
	for i, (df, max_freq)  in enumerate(zipped_data[:3]):
		data = df.dropna()
		freqs = ((max_freq-PUMP_FREQUENCY)-(data['tempV']-data['tempV'].min())*FREQVSVOLT- (data['currV']-data['currV'].min())*FREQVSCURR)
		color = colors[i]
		ax=plot_spline_fit(ax, x=freqs, y=data['ratio'], scolor=color, mfc=color,color=color, s=0.02, ms=5)

	#*-----------------------
	#* PARSING WAVEMETER DATA
 	#*-----------------------

	MEASURE_FOLDER = os.path.join(EXP_FOLDER, 'testPArun14')
	WDATA_FOLDER =os.path.join(MEASURE_FOLDER, 'testPArun14.csv')
	freq_data, max_freq, min_freq = add_wavemeter_data('', WDATA_FOLDER)
	data = freq_data[:]
	levels = staircase_fit(data)

	data = get_data_frame(MEASURE_FOLDER)
	data.dropna(inplace=True)
	freqs = ((max_freq)-(data['tempV']-data['tempV'].min())*FREQVSVOLT- (data['currV']-data['currV'].min())*FREQVSCURR)
	plt.plot(freqs)
 
	#*-----------------------
	#* GETTING DEPTH_RATIO DATAFRAME
 	#*-----------------------
	MEASURE_FOLDER = r'C:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\CATMeasurements\relScatRate'
	depth_ratios_df = get_rel_scattering_df(MEASURE_FOLDER)
	df_slice = depth_ratios_df[(depth_ratios_df['pa1']==1.85) & (depth_ratios_df['pd1']==84) & (depth_ratios_df['pd2'] == 84)]
	x = df_slice['pa2']
	y = df_slice['depth_ratio']
	plt.plot(x,y, 'o')

	#*-----------------------
	#* MEGA_RUN
 	#*-----------------------	
	MEASURE_FOLDER = os.path.join(EXP_FOLDER, 'testPARunMega')
	df = get_data_frame(MEASURE_FOLDER)
	df.dropna(inplace=True)

	df_grouped = df.groupby(by='pump_reference')
	min_ratios = df_grouped['ratio'].min()

	groups = dict(list(df_grouped))
	dfs = [df for df in groups.values()]
 
	max_freqs = [384182.5]*15
	#max_freqs=[384178.599, 384179.091, 384184.733]
	zipped_data = list(zip(dfs, max_freqs))
	fig, ax = plt.subplots()
	for i, (df, max_freq)  in enumerate(zipped_data[:]):
		data = df.dropna()
		freqs = ((max_freq-PUMP_FREQUENCY)-(data['tempV']-data['tempV'].min())*FREQVSVOLT- (data['currV']-data['currV'].min())*FREQVSCURR)
		ax=plot_spline_fit(ax, x=freqs, y=data['ratio'], yerr=data['ratioErr'],scolor=f'C{i}', mfc=f'C{i}',color=f'C{i}', s=0.0, ms=5, figsize=(10, 10), label=f"Pump Amplituide = { df.iloc[10]['pump_reference'] :.2f}", linewidth=2.5)

	plt.legend()

	plt.savefig(os.path.join(MEASURE_FOLDER, 'lossFeatures.png'))
	#*-----------------------
	#* MULTIPLE MEGARUN
	#*-----------------------
 
	folders = [os.path.join(EXP_FOLDER, path ) for path in ['testPArunMega', 'testPArunMega2']]
	dfs_mega = [get_data_frame(measure_folder, cache_all=True).dropna() for measure_folder in folders]

	dfs_grouped = [df_mega.groupby(by='pump_reference') for df_mega in dfs_mega]
	min_ratios = [df_grouped['ratio'].min() for df_grouped in dfs_grouped]

	groupss = [dict(list(df_grouped)) for df_grouped in dfs_grouped]
	dfs = [ [df for df in groups.values()] for groups in groupss]
 
	for row in dfs:
		x = [df['pump_reference'].mean() for df in row]
		y = [(df['ratio'].max() - df['ratio'].min())/df['motSS'].std() for df in row]
		plt.plot( x, y ,'-o', label=fr"$\delta$ = {180 - 2*row[0]['pump_AOM_freq'].mean()} MHz")
		plt.xlabel('Pump Amplitude')
		plt.ylabel(r'SNR $ = \frac{V_{ss, off} - V_{ss, on}}{\sigma_{V,off}}$ ')
	plt.legend()

def freq_misc():
	WDATA_FOLDER = r'C:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\CATMeasurements\CATcurrTestrun3.csv'
	freq_data = add_wavemeter_data('', WDATA_FOLDER)
	levels = staircase_fit(freq_data[0], peak_height=0.2, distance=50, data_offset=1, window_size=1) 

	plt.close()
 
	x = np.linspace(0, 4.9, 25)
	y = levels
 
	plt.plot(levels, '-o')
	plt.title('Levels plot')
	
	m, b, fit_line = my_linear_fit(x, y)
def save_fit_results(run_path, plot=False):
	filename = os.path.join(run_path, 'data.csv')
	bkfilename = os.path.join(run_path, 'data_oldPD.csv')
	settingsname = os.path.join(run_path, 'Settings.txt')
	
	dataHost = MTdataHost(SAMPLE_RATE)
	dataHost.loadCATdata(fileName=filename, settingsName=settingsname)
	dataHost.CATbackgroundData(bkfilename)
	
	dataHost.setAllCAT(0.002)
	resultDict = dataHost.getResults(run_path, store=True)
 
	if plot:
		dataHost.storeFits(run_path, combined=True, separate=True)
  
	return resultDict, dataHost.settings
		
def get_timestamp(run_path):
	timestamp = datetime.strptime(os.path.split(run_path)[-1].split('_')[0], dateformat)
	return timestamp

def extract_fit(run_path, plot=True, cache_failed=True, cache_all=True):
	"""Gather relevant data from each measurement run

	Args:
		run_path : absolute path to the run directory
		plot (bool, optional): plot fits. Defaults to True.
		cache_failed (bool, optional): Cache failed fits. If false, refit. Doesn't refit non-failed fits. Defaults to True.
		cache_all (bool, optional): If false, ignore any cached fit_results. Defaults to True.

	Returns:
		a 3-tuple (fit_results, settings, timestamp)
	"""
	fit_results, settings, timestamp = {}, {}, None
	
	if not os.path.isdir(run_path):
		return fit_results, settings, timestamp  # directory is not a run directory

	try:
		timestamp = get_timestamp(run_path)
  
  	# TODO: specify which error to catch
	except Exception as e:
		print("Error extracting timestamp from: ", run_path)
		print(traceback.format_exc())
	
	MAT_fit_cache_path = os.path.join(run_path, 'resultDict.txt')
 
	if not os.path.exists(MAT_fit_cache_path) or not cache_all:
		
		try: 
			fit_results, settings = save_fit_results(run_path, plot=plot)
		except Exception as e:
			print(traceback.format_exc())
			print("Fitting ERROR at ", os.path.basename(run_path), '\n')

			with open(MAT_fit_cache_path, 'w') as f:
				f.write(str('MAT fit failed'))
		
	else:
		print("Accessing cached results from :", os.path.basename(run_path))
  
		fit_results = open(MAT_fit_cache_path, 'r').read()

		if fit_results == 'MAT fit failed':
			if not cache_failed:
				# fit regardless of cached result
				try: 
					fit_results, settings = save_fit_results(run_path, plot=plot)
				except Exception as e:
					print(traceback.format_exc())
					print("Fitting ERROR at ", os.path.basename(run_path), '\n')
	
					with open(MAT_fit_cache_path, 'w') as f:
						f.write(str('MAT fit failed'))	
			else:
				print("Failed fit at :", os.path.basename(run_path))
				fit_results = {}

		else:
			fit_results = eval(open(MAT_fit_cache_path, 'r').read())
   
			settingsname = os.path.join(run_path, 'Settings.txt')
			settings = eval(open(settingsname, 'r').read())
   
	return fit_results, settings, timestamp



def get_row(run_path, **kwargs):
			
   fit_results, settings, timestamp = extract_fit(run_path, **kwargs)
   row = {**fit_results, **settings, **{'timestamp':timestamp}}
   
   return row

   
def get_data_frame(data_dir, parallel=True, in_process_run=False, **kwargs):
   
	run_path_arr = []
	rows = []
	
	for relative_path in os.listdir(data_dir):
		run_path_arr.append(os.path.join(data_dir, relative_path))
  
	if in_process_run:
		run_path_arr.pop()

	run_path_arr = sorted(run_path_arr)
	
	if parallel:
		with Pool(4) as p:
			rows = list(tqdm(p.imap(partial(get_row, **kwargs), run_path_arr), total=len(run_path_arr)))
	
	else:
		for run_path in tqdm(run_path_arr):
		   rows.append(get_row(run_path, **kwargs))

	return pd.DataFrame.from_dict(rows)

def add_wavemeter_data(df, wmeter_csv_path, window_size=100, num_rows=50):


	"""Extract unique frequnecy values from wavemeter data
	Returns:
		unique_levels (list): unique frequency values in wavemeter data
	"""
 
	# TODO: modify dataframe in place with frequency data
 
	wdata = pd.read_csv(wmeter_csv_path, skiprows=2)
	wdata.dropna(inplace=True)
	freq_data = np.array(wdata.iloc[:, 0])
	try:
		freq_data = np.array([float(item) for item in freq_data if item.replace('.','').isdigit()])
	except Exception as e:
		print(e)
 
	max_freq = freq_data.max()
	min_freq = freq_data.min()

	return freq_data, max_freq, min_freq

def plot_results(ax, dfs, max_freq, min_freq=0.0, mfc='red', fmt='o', ms=5, save_folder=False, xscale=1.0, yscale=1.0, **kwargs):
	FREQVSVOLT = 221.0 
	FREQVSCURR = 1.13
	
	if not type(dfs) == list:
		freqs = ((max_freq-PUMP_FREQUENCY)-(dfs.dropna()['tempV']-dfs.dropna()['tempV'].min())*FREQVSVOLT- (dfs.dropna()['currV']-dfs.dropna()['currV'].min())*FREQVSCURR)*xscale
		dfs=[dfs]
  
	plt.gcf().set_dpi(300)
	
	for df in dfs:
		df = df.dropna()
		ax.errorbar(freqs, 
			   df['ratio']*yscale,
			   yerr=df['ratioErr'],
			   fmt=fmt, mfc=mfc, color='black', ms=ms, **kwargs)
		ax.set_ylabel(r'$\mathbf{\frac{V_{ss, cat}}{V_{ss}}} $ ', **labeldict)
		ax.set_xlabel(r'$\Delta $ (GHz)', **labeldict)
	
	if save_folder:
		plt.savefig(os.path.join(save_folder, 'ratio_vs_freq.png'))
	
	return freqs, ax
  
	#return plt.gca(), plt.gcf()
	#plt.show()

def plot_spline_fit(ax, x, y, s=1, yerr=None, color='black', scolor='black',figsize=(12,5), save_folder=None, title='',alpha=0.5,dpi=200, label='plot',**kwargs):
	from scipy.interpolate import splev, splrep
	xnew = np.linspace(min(x), max(x), 3*len(x) )

	y = [b for a,b in sorted(zip(x,y), key=lambda pair: pair[0])]
	if yerr is not None:
		yerr = [b for a,b in sorted(zip(x,yerr), key=lambda pair: pair[0])]
 
	x = sorted(x)

	spl = splrep(x, y, s=s)
	ynew = splev(xnew, spl)

	
	plt.gcf().set_dpi(dpi)
	plt.gcf().set_size_inches(figsize)
	
	if yerr is not None:
		ax.errorbar(x, y, yerr=yerr, fmt='o', **kwargs)
	else:
		ax.plot(x,y, 'o', **kwargs)
	ax.plot(xnew, ynew, '-', color=scolor, alpha=alpha, label=label, **kwargs)
 
	ax.set_ylabel(r'$\mathbf{\frac{V_{ss, cat}}{V_{ss}}} $ ', **labeldict)
	ax.set_xlabel(r'$\Delta $ (GHz)', **labeldict)
 
	ax.set_title(title, **titledict)
	if save_folder:
		plt.savefig(os.path.join(save_folder, 'spline_ratio_vs_freq.png'))
	
	return ax
 
def plot_polyfit(x_data, y_data, spline_degree):
	
	coefficients = np.polyfit(x_data, y_data, spline_degree)

	x_interp = np.linspace(min(x_data), max(x_data), 100)
	y_interp = np.polyval(coefficients, x_interp)

	plt.scatter(x_data, y_data, label='Original Data')
	plt.plot(x_interp, y_interp, label='Polynomial Interpolation (Degree={})'.format(spline_degree))

def collect_plots(source, destination, plot_name):
	print(f'Collecting plots from {os.path.basename(source)}')
	import shutil

	os.makedirs(destination, exist_ok=True)

	plot_files = []
	for root, dirs, files in os.walk(source):
		
		for file in files:
			if file == plot_name:
				plot_files.append(os.path.join(root, file))

	for i, plot_file in enumerate(plot_files, start=0):
		new_filename = f'{i}{plot_name}'
		destination_path = os.path.join(destination, new_filename)
		shutil.copy(plot_file, destination_path)

def create_GIF(images_folder, image_name):
	import imageio
	with imageio.get_writer(os.path.join(images_folder, f'{image_name}movie.gif'), mode='I', duration=0.5) as writer:
		for filename in os.listdir(images_folder):
			if image_name in filename:
				image = imageio.imread(os.path.join(images_folder, filename))
				writer.append_data(image)

def staircase_fit(data, peak_height=0.1, distance=100, data_offset=1, window_size=1, inc_final_peak=True):
	def moving_average(arr, window_size):
		weights = np.ones(window_size) / window_size
		return np.convolve(arr, weights, mode='valid')

	convdata1 = moving_average(data, window_size)
	convdata2 = moving_average(data[data_offset+1:], window_size )
	final = convdata1[:len(convdata2)]-convdata2
	# plt.plot(data)
	# plt.plot(convdata1)
	# plt.plot(convdata2)
	# plt.show()
	# plt.plot(final)

	
	from scipy.signal import find_peaks
	x= final
	peaks, _ = find_peaks(x, height=peak_height, distance=distance)
	peaks = np.insert(peaks, 0, 0)
	levels = []
	plot_arr = []
	for i, peak in enumerate(peaks):
		
		if i < len(peaks) - 1:
			temp = data[ peaks[i]:peaks[i+1] ]
			plot_arr.extend( np.ones_like(temp)*np.mean(temp))
			levels.append(np.mean(temp))
	if inc_final_peak:
		temp = data[peaks[-1]:]
		levels.append(np.mean(temp))
		plot_arr.extend( np.ones_like(temp)*np.mean(temp))
  
	plt.plot(x)
	plt.plot(peaks, x[peaks], "x")
	plt.plot(np.zeros_like(x), "--", color="gray")
	plt.show()
	
	plt.plot(data)
	plt.plot(np.ravel((plot_arr)))
	plt.show()
	plt.close()
	plt.plot(np.array(levels)[np.where(abs(np.diff(levels))>0.05)[0]], 'o', ms=5)
 
	return levels

def load_single_run(run_path):
	filename = os.path.join(run_path, 'data.csv')
	bkfilename = os.path.join(run_path, 'data_oldPD.csv')
	settingsname = os.path.join(run_path, 'Settings.txt')
	
	dh1 = MTdataHost(SAMPLE_RATE)
	dh1.loadCATdata(fileName=filename, settingsName=settingsname)
	
	return dh1
	# *-----------------------
	# *RELATIVE SCATTERING RATE
	# *-----------------------


def get_rel_scattering_df(data_folder):
	depth_ratios_df = []
	listdir = sorted(os.listdir(data_folder))
	try:
		for run_folder1, run_folder2 in [listdir[i:i+2] for i in range(len(listdir))[::2]]:
			try:
				run_path1 = os.path.join(data_folder, run_folder1)
				run_path2 = os.path.join(data_folder, run_folder2)
				result = {}
				with open(os.path.join(run_path1, 'twoSettings.txt'), 'r') as f:
					settings = f.read() 
					import re

					pattern = r'(\w+)\s*=\s*\(([\d.]+),\s*([\d.]+)\)'

					matches = re.findall(pattern, settings)

					
					for match in matches:
						key = match[0]
						value1 = float(match[1])
						value2 = float(match[2])
						result[key] = (value1, value2)

					print(result)
				with open(os.path.join(run_path2, 'twoSettings.txt'), 'r') as f:
					pass
					#print(f.readlines())
				
				timestamp = get_timestamp(run_path)
				fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
				
				extracted_values = {
						'pa1': result['pd1'][0],
						'pd1': result['pd1'][1],
						'pa2': result['pd2'][0],
						'pd2': result['pd2'][1],
						'depth_ratio': 1/float(depth_ratio), # ratio between current and std settings
      					'timestamp': timestamp
					}
				depth_ratios_df.append(extracted_values)
				
				print('\n')
			except Exception as e:
					print(traceback.format_exc())
					print(f'Error {e} at {run_folder1, run_folder2}')
	except Exception as e:
		print(f'Error {e}')

	depth_ratios_df = pd.DataFrame(depth_ratios_df)
 
	return depth_ratios_df

def get_rel_scattering(run_path1, run_path2):
	resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
	resultDict2, scat_ratio2 = _load_single_run_rel_scat(run_path2, plot=True)
	
	print(f"scat_ratio 1, (2 inverted) = {scat_ratio1:.3f}, {1/scat_ratio2:.3f}")
	scat_ratio_avg = (scat_ratio1+1/scat_ratio2)/2
	
	Rratio = resultDict1['initMOTR']/resultDict2['initMOTR']
	print(fr"Rratio = {resultDict1['initMOTR']:.3f} / {resultDict2['initMOTR']:.3f} = {Rratio:.3f}")
	depthRatio = np.sqrt(Rratio/scat_ratio_avg)
	
	return resultDict1, resultDict2, depthRatio


def _load_single_run_rel_scat(run_path, plot=False, cache_all=False):
	filename = os.path.join(run_path, 'data.csv')
	settingsname = os.path.join(run_path, 'Settings.txt')
	
	MAT_fit_cache_path = os.path.join(run_path, 'resultDict.txt')
	fit_results = {}
	if not os.path.exists(MAT_fit_cache_path) or not cache_all:
		
		try: 
			dh1 = MTdataHost(SAMPLE_RATE)
			dh1.loadCATdata(fileName=filename, settingsName=settingsname)

			dh1.tBaseline = 1
			dh1.tLoad = 2
			dh1.timeLoad = 30
			dh1.tReload = dh1.tLoad + dh1.timeLoad
			dh1.timeReload = 1
			dh1.tCATbackground = dh1.tReload + dh1.timeReload

			#dh1.setOffset()
			#dh1.setCATtiming()
			dh1.setAllCAT(0.002)

			print('FITTINGGGGGGGGGGGG')
			fit_results = dh1.getResults(run_path, store=True)
			if plot:
				dh1.storeFits(run_path, combined=True, separate=False)
		except Exception as e:
			print(traceback.format_exc())
			print("Fitting ERROR at ", os.path.basename(run_path), '\n')

			with open(MAT_fit_cache_path, 'w') as f:
				f.write(str('MAT fit failed'))
		
	else:
		print("Accessing cached results from :", os.path.basename(run_path))

		fit_results = open(MAT_fit_cache_path, 'r').read()

		if fit_results == 'MAT fit failed':
			print("Failed fit at :", os.path.basename(run_path))
			fit_results = {}

		else:
			fit_results = eval(open(MAT_fit_cache_path, 'r').read())


	
	scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
	fit_results['scat_ratio'] = scat_ratio
 	#scat_ratio = dh1.motSS/(dh1.reloadVolt+dh1.baseVolt - (dh1.CATbackgroundVolt+dh1.noLightBackground))
	
	return fit_results, scat_ratio

def scat_rate(I, delta, gamma=6.065, Is=1.669):
	"""_summary_

	Args:
		I (float): intensity (Mhz)
		delta (float): detuning (Mhz)
		gamma (float, optional): linewidth (Mhz) Defaults to 6.065.
		Is (float, optional): Should be one of 3.576(isotropic), 2.503(pi), 1.669 (sigma+-). Defaults to 1.669.

	Returns:
		_type_: gamma: the scattering rate
	"""
	return gamma*I/(2*Is*(1+I/Is+4*(delta/gamma)**2))

if __name__ == '__main__':
	run_path = r"C:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\CATMeasurements\testPArun9\16-53-10"
	filename = os.path.join(run_path, 'data.csv')
	bkfilename = os.path.join(run_path, 'data_oldPD.csv')
	settingsname = os.path.join(run_path, 'Settings.txt')
	
	dh1 = MTdataHost(SAMPLE_RATE)
	dh1.loadCATdata(fileName=filename, settingsName=settingsname)
	
 	#dh1.CATbackgroundData(bkfilename)
	dh1.setAllCAT(0.002)
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
In [ ]:
get_rel_scattering_df(r'C:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\CATMeasurements\relScatRate\TrapDepthMap')
{'pd1': (1.85, 84.0), 'pd2': (1.125, 82.4)}
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
scat_ratio 1, (2 inverted) = 1.652, 1.621
Rratio = 0.014 / 0.010 = 1.456


{'pd1': (1.85, 84.0), 'pd2': (1.125, 80.8)}
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
scat_ratio 1, (2 inverted) = 2.086, 2.015
Rratio = 0.015 / 0.005 = 2.946


{'pd1': (1.85, 84.0), 'pd2': (1.125, 86.4)}
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
---------------------------------------------------------------------------
KeyboardInterrupt                         Traceback (most recent call last)
Cell In[47], line 1
----> 1 get_rel_scattering_df(r'C:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\CATMeasurements\relScatRate\TrapDepthMap')

Cell In[46], line 491, in get_rel_scattering_df(data_folder)
    488 					#print(f.readlines())
    490 				timestamp = get_timestamp(run_path)
--> 491 				fit_results1, fit_results2, depth_ratio = get_rel_scattering(run_path1, run_path2)
    493 				extracted_values = {
    494 						'pa1': result['pd1'][0],
    495 						'pd1': result['pd1'][1],
   (...)
    499       					'timestamp': timestamp
    500 					}
    501 				depth_ratios_df.append(extracted_values)

Cell In[46], line 516, in get_rel_scattering(run_path1, run_path2)
    514 def get_rel_scattering(run_path1, run_path2):
    515 	resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
--> 516 	resultDict2, scat_ratio2 = _load_single_run_rel_scat(run_path2, plot=True)
    518 	print(f"scat_ratio 1, (2 inverted) = {scat_ratio1:.3f}, {1/scat_ratio2:.3f}")
    519 	scat_ratio_avg = (scat_ratio1+1/scat_ratio2)/2

Cell In[46], line 554, in _load_single_run_rel_scat(run_path, plot, cache_all)
    552 	fit_results = dh1.getResults(run_path, store=True)
    553 	if plot:
--> 554 		dh1.storeFits(run_path, combined=True, separate=False)
    555 except Exception as e:
    556 	print(traceback.format_exc())

File c:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\analysis\MT_class_PID_new.py:810, in MTdataHost.storeFits(self, dirName, combined, separate)
    <a href='file:///c%3A/Users/svars/OneDrive/Desktop/UBC%20Lab/CATExperiment/analysis/MT_class_PID_new.py?line=806'>807</a> 	plt.plot(self.CATbackgroundTime,self.CATbackgroundVoltage, c='pink')
    <a href='file:///c%3A/Users/svars/OneDrive/Desktop/UBC%20Lab/CATExperiment/analysis/MT_class_PID_new.py?line=807'>808</a> 	plt.plot(self.initTime, self.initFit[2], color='grey')
--> <a href='file:///c%3A/Users/svars/OneDrive/Desktop/UBC%20Lab/CATExperiment/analysis/MT_class_PID_new.py?line=809'>810</a> 	plt.savefig(os.path.join(dirName,'fits.png'), dpi=400)
    <a href='file:///c%3A/Users/svars/OneDrive/Desktop/UBC%20Lab/CATExperiment/analysis/MT_class_PID_new.py?line=810'>811</a> 	plt.close()
    <a href='file:///c%3A/Users/svars/OneDrive/Desktop/UBC%20Lab/CATExperiment/analysis/MT_class_PID_new.py?line=812'>813</a> if separate:

File c:\ProgramData\Anaconda3\envs\magpy_env\Lib\site-packages\matplotlib\pyplot.py:1023, in savefig(*args, **kwargs)
   <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/pyplot.py?line=1019'>1020</a> @_copy_docstring_and_deprecators(Figure.savefig)
   <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/pyplot.py?line=1020'>1021</a> def savefig(*args, **kwargs):
   <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/pyplot.py?line=1021'>1022</a>     fig = gcf()
-> <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/pyplot.py?line=1022'>1023</a>     res = fig.savefig(*args, **kwargs)
   <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/pyplot.py?line=1023'>1024</a>     fig.canvas.draw_idle()  # Need this if 'transparent=True', to reset colors.
   <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/pyplot.py?line=1024'>1025</a>     return res

File c:\ProgramData\Anaconda3\envs\magpy_env\Lib\site-packages\matplotlib\figure.py:3343, in Figure.savefig(self, fname, transparent, **kwargs)
   <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/figure.py?line=3338'>3339</a>     for ax in self.axes:
   <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/figure.py?line=3339'>3340</a>         stack.enter_context(
   <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/figure.py?line=3340'>3341</a>             ax.patch._cm_set(facecolor='none', edgecolor='none'))
-> <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/figure.py?line=3342'>3343</a> self.canvas.print_figure(fname, **kwargs)

File c:\ProgramData\Anaconda3\envs\magpy_env\Lib\site-packages\matplotlib\backend_bases.py:2366, in FigureCanvasBase.print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, bbox_inches, pad_inches, bbox_extra_artists, backend, **kwargs)
   <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/backend_bases.py?line=2361'>2362</a> try:
   <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/backend_bases.py?line=2362'>2363</a>     # _get_renderer may change the figure dpi (as vector formats
   <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/backend_bases.py?line=2363'>2364</a>     # force the figure dpi to 72), so we need to set it again here.
   <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/backend_bases.py?line=2364'>2365</a>     with cbook._setattr_cm(self.figure, dpi=dpi):
-> <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/backend_bases.py?line=2365'>2366</a>         result = print_method(
   <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/backend_bases.py?line=2366'>2367</a>             filename,
   <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/backend_bases.py?line=2367'>2368</a>             facecolor=facecolor,
   <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/backend_bases.py?line=2368'>2369</a>             edgecolor=edgecolor,
   <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/backend_bases.py?line=2369'>2370</a>             orientation=orientation,
   <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/backend_bases.py?line=2370'>2371</a>             bbox_inches_restore=_bbox_inches_restore,
   <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/backend_bases.py?line=2371'>2372</a>             **kwargs)
   <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/backend_bases.py?line=2372'>2373</a> finally:
   <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/backend_bases.py?line=2373'>2374</a>     if bbox_inches and restore_bbox:

File c:\ProgramData\Anaconda3\envs\magpy_env\Lib\site-packages\matplotlib\backend_bases.py:2232, in FigureCanvasBase._switch_canvas_and_return_print_method.<locals>.<lambda>(*args, **kwargs)
   <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/backend_bases.py?line=2227'>2228</a>     optional_kws = {  # Passed by print_figure for other renderers.
   <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/backend_bases.py?line=2228'>2229</a>         "dpi", "facecolor", "edgecolor", "orientation",
   <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/backend_bases.py?line=2229'>2230</a>         "bbox_inches_restore"}
   <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/backend_bases.py?line=2230'>2231</a>     skip = optional_kws - {*inspect.signature(meth).parameters}
-> <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/backend_bases.py?line=2231'>2232</a>     print_method = functools.wraps(meth)(lambda *args, **kwargs: meth(
   <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/backend_bases.py?line=2232'>2233</a>         *args, **{k: v for k, v in kwargs.items() if k not in skip}))
   <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/backend_bases.py?line=2233'>2234</a> else:  # Let third-parties do as they see fit.
   <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/backend_bases.py?line=2234'>2235</a>     print_method = meth

File c:\ProgramData\Anaconda3\envs\magpy_env\Lib\site-packages\matplotlib\backends\backend_agg.py:509, in FigureCanvasAgg.print_png(self, filename_or_obj, metadata, pil_kwargs)
    <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/backends/backend_agg.py?line=461'>462</a> def print_png(self, filename_or_obj, *, metadata=None, pil_kwargs=None):
    <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/backends/backend_agg.py?line=462'>463</a>     """
    <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/backends/backend_agg.py?line=463'>464</a>     Write the figure to a PNG file.
    <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/backends/backend_agg.py?line=464'>465</a> 
   (...)
    <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/backends/backend_agg.py?line=506'>507</a>         *metadata*, including the default 'Software' key.
    <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/backends/backend_agg.py?line=507'>508</a>     """
--> <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/backends/backend_agg.py?line=508'>509</a>     self._print_pil(filename_or_obj, "png", pil_kwargs, metadata)

File c:\ProgramData\Anaconda3\envs\magpy_env\Lib\site-packages\matplotlib\backends\backend_agg.py:457, in FigureCanvasAgg._print_pil(self, filename_or_obj, fmt, pil_kwargs, metadata)
    <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/backends/backend_agg.py?line=451'>452</a> def _print_pil(self, filename_or_obj, fmt, pil_kwargs, metadata=None):
    <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/backends/backend_agg.py?line=452'>453</a>     """
    <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/backends/backend_agg.py?line=453'>454</a>     Draw the canvas, then save it using `.image.imsave` (to which
    <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/backends/backend_agg.py?line=454'>455</a>     *pil_kwargs* and *metadata* are forwarded).
    <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/backends/backend_agg.py?line=455'>456</a>     """
--> <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/backends/backend_agg.py?line=456'>457</a>     FigureCanvasAgg.draw(self)
    <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/backends/backend_agg.py?line=457'>458</a>     mpl.image.imsave(
    <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/backends/backend_agg.py?line=458'>459</a>         filename_or_obj, self.buffer_rgba(), format=fmt, origin="upper",
    <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/backends/backend_agg.py?line=459'>460</a>         dpi=self.figure.dpi, metadata=metadata, pil_kwargs=pil_kwargs)

File c:\ProgramData\Anaconda3\envs\magpy_env\Lib\site-packages\matplotlib\backends\backend_agg.py:400, in FigureCanvasAgg.draw(self)
    <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/backends/backend_agg.py?line=395'>396</a> # Acquire a lock on the shared font cache.
    <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/backends/backend_agg.py?line=396'>397</a> with RendererAgg.lock, \
    <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/backends/backend_agg.py?line=397'>398</a>      (self.toolbar._wait_cursor_for_draw_cm() if self.toolbar
    <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/backends/backend_agg.py?line=398'>399</a>       else nullcontext()):
--> <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/backends/backend_agg.py?line=399'>400</a>     self.figure.draw(self.renderer)
    <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/backends/backend_agg.py?line=400'>401</a>     # A GUI class may be need to update a window using this draw, so
    <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/backends/backend_agg.py?line=401'>402</a>     # don't forget to call the superclass.
    <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/backends/backend_agg.py?line=402'>403</a>     super().draw()

File c:\ProgramData\Anaconda3\envs\magpy_env\Lib\site-packages\matplotlib\artist.py:95, in _finalize_rasterization.<locals>.draw_wrapper(artist, renderer, *args, **kwargs)
     <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/artist.py?line=92'>93</a> @wraps(draw)
     <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/artist.py?line=93'>94</a> def draw_wrapper(artist, renderer, *args, **kwargs):
---> <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/artist.py?line=94'>95</a>     result = draw(artist, renderer, *args, **kwargs)
     <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/artist.py?line=95'>96</a>     if renderer._rasterizing:
     <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/artist.py?line=96'>97</a>         renderer.stop_rasterizing()

File c:\ProgramData\Anaconda3\envs\magpy_env\Lib\site-packages\matplotlib\artist.py:72, in allow_rasterization.<locals>.draw_wrapper(artist, renderer)
     <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/artist.py?line=68'>69</a>     if artist.get_agg_filter() is not None:
     <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/artist.py?line=69'>70</a>         renderer.start_filter()
---> <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/artist.py?line=71'>72</a>     return draw(artist, renderer)
     <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/artist.py?line=72'>73</a> finally:
     <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/artist.py?line=73'>74</a>     if artist.get_agg_filter() is not None:

File c:\ProgramData\Anaconda3\envs\magpy_env\Lib\site-packages\matplotlib\figure.py:3140, in Figure.draw(self, renderer)
   <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/figure.py?line=3136'>3137</a>         # ValueError can occur when resizing a window.
   <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/figure.py?line=3138'>3139</a> self.patch.draw(renderer)
-> <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/figure.py?line=3139'>3140</a> mimage._draw_list_compositing_images(
   <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/figure.py?line=3140'>3141</a>     renderer, self, artists, self.suppressComposite)
   <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/figure.py?line=3142'>3143</a> for sfig in self.subfigs:
   <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/figure.py?line=3143'>3144</a>     sfig.draw(renderer)

File c:\ProgramData\Anaconda3\envs\magpy_env\Lib\site-packages\matplotlib\image.py:131, in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
    <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/image.py?line=128'>129</a> if not_composite or not has_images:
    <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/image.py?line=129'>130</a>     for a in artists:
--> <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/image.py?line=130'>131</a>         a.draw(renderer)
    <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/image.py?line=131'>132</a> else:
    <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/image.py?line=132'>133</a>     # Composite any adjacent images together
    <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/image.py?line=133'>134</a>     image_group = []

File c:\ProgramData\Anaconda3\envs\magpy_env\Lib\site-packages\matplotlib\artist.py:72, in allow_rasterization.<locals>.draw_wrapper(artist, renderer)
     <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/artist.py?line=68'>69</a>     if artist.get_agg_filter() is not None:
     <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/artist.py?line=69'>70</a>         renderer.start_filter()
---> <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/artist.py?line=71'>72</a>     return draw(artist, renderer)
     <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/artist.py?line=72'>73</a> finally:
     <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/artist.py?line=73'>74</a>     if artist.get_agg_filter() is not None:

File c:\ProgramData\Anaconda3\envs\magpy_env\Lib\site-packages\matplotlib\axes\_base.py:3064, in _AxesBase.draw(self, renderer)
   <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/axes/_base.py?line=3060'>3061</a> if artists_rasterized:
   <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/axes/_base.py?line=3061'>3062</a>     _draw_rasterized(self.figure, artists_rasterized, renderer)
-> <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/axes/_base.py?line=3063'>3064</a> mimage._draw_list_compositing_images(
   <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/axes/_base.py?line=3064'>3065</a>     renderer, self, artists, self.figure.suppressComposite)
   <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/axes/_base.py?line=3066'>3067</a> renderer.close_group('axes')
   <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/axes/_base.py?line=3067'>3068</a> self.stale = False

File c:\ProgramData\Anaconda3\envs\magpy_env\Lib\site-packages\matplotlib\image.py:131, in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
    <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/image.py?line=128'>129</a> if not_composite or not has_images:
    <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/image.py?line=129'>130</a>     for a in artists:
--> <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/image.py?line=130'>131</a>         a.draw(renderer)
    <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/image.py?line=131'>132</a> else:
    <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/image.py?line=132'>133</a>     # Composite any adjacent images together
    <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/image.py?line=133'>134</a>     image_group = []

File c:\ProgramData\Anaconda3\envs\magpy_env\Lib\site-packages\matplotlib\artist.py:72, in allow_rasterization.<locals>.draw_wrapper(artist, renderer)
     <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/artist.py?line=68'>69</a>     if artist.get_agg_filter() is not None:
     <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/artist.py?line=69'>70</a>         renderer.start_filter()
---> <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/artist.py?line=71'>72</a>     return draw(artist, renderer)
     <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/artist.py?line=72'>73</a> finally:
     <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/artist.py?line=73'>74</a>     if artist.get_agg_filter() is not None:

File c:\ProgramData\Anaconda3\envs\magpy_env\Lib\site-packages\matplotlib\collections.py:972, in _CollectionWithSizes.draw(self, renderer)
    <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/collections.py?line=968'>969</a> @artist.allow_rasterization
    <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/collections.py?line=969'>970</a> def draw(self, renderer):
    <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/collections.py?line=970'>971</a>     self.set_sizes(self._sizes, self.figure.dpi)
--> <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/collections.py?line=971'>972</a>     super().draw(renderer)

File c:\ProgramData\Anaconda3\envs\magpy_env\Lib\site-packages\matplotlib\artist.py:72, in allow_rasterization.<locals>.draw_wrapper(artist, renderer)
     <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/artist.py?line=68'>69</a>     if artist.get_agg_filter() is not None:
     <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/artist.py?line=69'>70</a>         renderer.start_filter()
---> <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/artist.py?line=71'>72</a>     return draw(artist, renderer)
     <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/artist.py?line=72'>73</a> finally:
     <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/artist.py?line=73'>74</a>     if artist.get_agg_filter() is not None:

File c:\ProgramData\Anaconda3\envs\magpy_env\Lib\site-packages\matplotlib\collections.py:417, in Collection.draw(self, renderer)
    <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/collections.py?line=407'>408</a> else:
    <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/collections.py?line=408'>409</a>     renderer.draw_path_collection(
    <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/collections.py?line=409'>410</a>         gc, transform.frozen(), paths,
    <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/collections.py?line=410'>411</a>         self.get_transforms(), offsets, offset_trf,
   (...)
    <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/collections.py?line=413'>414</a>         self._antialiaseds, self._urls,
    <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/collections.py?line=414'>415</a>         "screen")  # offset_position, kept for backcompat.
--> <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/collections.py?line=416'>417</a> gc.restore()
    <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/collections.py?line=417'>418</a> renderer.close_group(self.__class__.__name__)
    <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/collections.py?line=418'>419</a> self.stale = False

File c:\ProgramData\Anaconda3\envs\magpy_env\Lib\site-packages\matplotlib\backend_bases.py:801, in GraphicsContextBase.restore(self)
    <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/backend_bases.py?line=797'>798</a>     self._snap = gc._snap
    <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/backend_bases.py?line=798'>799</a>     self._sketch = gc._sketch
--> <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/backend_bases.py?line=800'>801</a> def restore(self):
    <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/backend_bases.py?line=801'>802</a>     """
    <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/backend_bases.py?line=802'>803</a>     Restore the graphics context from the stack - needed only
    <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/backend_bases.py?line=803'>804</a>     for backends that save graphics contexts on a stack.
    <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/backend_bases.py?line=804'>805</a>     """
    <a href='file:///c%3A/ProgramData/Anaconda3/envs/magpy_env/Lib/site-packages/matplotlib/backend_bases.py?line=806'>807</a> def get_alpha(self):

KeyboardInterrupt: 
In [ ]:
import seaborn as sns
scat_df = get_rel_scattering_df(r'C:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\CATMeasurements\relScatRate\TrapDepthMap')
pivot_table = scat_df.pivot('pa2', 'pd2', 'depth_ratio')
sns.heatmap(pivot_table, annot=True, fmt='.2f', cmap='magma')
plt.grid()
  0%|          | 0/121 [00:00<?, ?it/s]<ipython-input-64-1a272312f3b3>:523: RuntimeWarning: invalid value encountered in sqrt
  depthRatio = np.sqrt(Rratio/scat_ratio_avg)
 29%|██▉       | 35/121 [00:00<00:00, 347.96it/s]
{'pd1': (1.85, 84.0), 'pd2': (1.125, 82.4)}
Accessing cached results from : 17-56-41
Accessing cached results from : 17-57-25
scat_ratio 1, (2 inverted) = 1.652, 1.621
Rratio = 0.014 / 0.010 = 1.456


{'pd1': (1.85, 84.0), 'pd2': (1.125, 80.8)}
Accessing cached results from : 17-58-10
Accessing cached results from : 17-58-54
scat_ratio 1, (2 inverted) = 2.086, 2.015
Rratio = 0.015 / 0.005 = 2.946


{'pd1': (1.85, 84.0), 'pd2': (1.125, 86.4)}
Accessing cached results from : 17-59-38
Accessing cached results from : 18-00-22
scat_ratio 1, (2 inverted) = 0.913, 0.914
Rratio = 0.014 / 0.006 = 2.472


{'pd1': (1.85, 84.0), 'pd2': (1.125, 85.6)}
Accessing cached results from : 18-01-06
Accessing cached results from : 18-01-50
scat_ratio 1, (2 inverted) = 0.981, 0.958
Rratio = 0.013 / 0.007 = 1.829


{'pd1': (1.85, 84.0), 'pd2': (1.125, 80.0)}
Accessing cached results from : 18-02-39
Accessing cached results from : 18-03-31
scat_ratio 1, (2 inverted) = 2.408, 2.328
Rratio = 0.012 / 0.002 = 7.372


{'pd1': (1.85, 84.0), 'pd2': (1.125, 84.0)}
Accessing cached results from : 18-04-24
Accessing cached results from : 18-05-17
scat_ratio 1, (2 inverted) = 1.294, 1.238
Rratio = 0.013 / 0.009 = 1.435


{'pd1': (1.85, 84.0), 'pd2': (1.125, 81.6)}
Accessing cached results from : 18-06-11
Accessing cached results from : 18-07-04
scat_ratio 1, (2 inverted) = 1.872, 1.779
Rratio = 0.012 / 0.004 = 3.021


{'pd1': (1.85, 84.0), 'pd2': (1.125, 83.2)}
Accessing cached results from : 18-07-59
Accessing cached results from : 18-08-51
scat_ratio 1, (2 inverted) = 1.401, 1.371
Rratio = 0.011 / 0.009 = 1.218


{'pd1': (1.85, 84.0), 'pd2': (1.125, 88.0)}
Accessing cached results from : 18-09-42
Accessing cached results from : 18-10-35
scat_ratio 1, (2 inverted) = 0.950, 0.230
Rratio = 0.012 / 0.000 = 27.840


{'pd1': (1.85, 84.0), 'pd2': (1.125, 87.2)}
Accessing cached results from : 18-11-29
Accessing cached results from : 18-12-22
scat_ratio 1, (2 inverted) = 0.881, 0.885
Rratio = 0.012 / 0.003 = 3.479


{'pd1': (1.85, 84.0), 'pd2': (1.125, 84.8)}
Accessing cached results from : 18-13-17
Accessing cached results from : 18-14-10
scat_ratio 1, (2 inverted) = 1.111, 1.113
Rratio = 0.012 / 0.008 = 1.473


{'pd1': (1.85, 84.0), 'pd2': (0.6900000000000001, 82.4)}
Accessing cached results from : 18-15-02
Accessing cached results from : 18-15-55
scat_ratio 1, (2 inverted) = 2.319, 2.136
Rratio = 0.012 / 0.005 = 2.264


{'pd1': (1.85, 84.0), 'pd2': (0.6900000000000001, 80.8)}
Accessing cached results from : 18-16-49
Accessing cached results from : 18-17-41
scat_ratio 1, (2 inverted) = 2.958, 2.682
Rratio = 0.011 / -0.001 = -18.151


{'pd1': (1.85, 84.0), 'pd2': (0.6900000000000001, 86.4)}
Accessing cached results from : 18-18-33
Accessing cached results from : 18-19-25
scat_ratio 1, (2 inverted) = 1.061, 1.081
Rratio = 0.012 / 0.004 = 3.427


{'pd1': (1.85, 84.0), 'pd2': (0.6900000000000001, 85.6)}
Accessing cached results from : 18-20-18
Accessing cached results from : 18-21-10
scat_ratio 1, (2 inverted) = 1.252, 1.254
Rratio = 0.012 / 0.005 = 2.668


{'pd1': (1.85, 84.0), 'pd2': (0.6900000000000001, 80.0)}
Accessing cached results from : 18-22-04
Accessing cached results from : 18-22-56
scat_ratio 1, (2 inverted) = 3.387, 3.062
Rratio = 0.013 / 0.003 = 5.029


{'pd1': (1.85, 84.0), 'pd2': (0.6900000000000001, 84.0)}
Accessing cached results from : 18-23-50
Accessing cached results from : 18-24-46
scat_ratio 1, (2 inverted) = 1.749, 1.756
Rratio = 0.013 / 0.005 = 2.631


{'pd1': (1.85, 84.0), 'pd2': (0.6900000000000001, 81.6)}
Accessing cached results from : 18-25-41
Accessing cached results from : 18-26-35
scat_ratio 1, (2 inverted) = 2.601, 2.552
Rratio = 0.013 / 0.001 = 11.784


{'pd1': (1.85, 84.0), 'pd2': (0.6900000000000001, 83.2)}
Accessing cached results from : 18-27-30
Accessing cached results from : 18-28-23
scat_ratio 1, (2 inverted) = 1.941, 1.955
Rratio = 0.013 / 0.005 = 2.428


{'pd1': (1.85, 84.0), 'pd2': (0.6900000000000001, 88.0)}
Accessing cached results from : 18-29-14
Accessing cached results from : 18-30-07
scat_ratio 1, (2 inverted) = 0.948, 1.007
Rratio = 0.014 / 0.001 = 12.414


{'pd1': (1.85, 84.0), 'pd2': (0.6900000000000001, 87.2)}
Accessing cached results from : 18-30-58
Accessing cached results from : 18-31-50
scat_ratio 1, (2 inverted) = 0.964, 0.978
Rratio = 0.014 / 0.003 = 5.300


{'pd1': (1.85, 84.0), 'pd2': (0.6900000000000001, 84.8)}
Accessing cached results from : 18-32-43
Accessing cached results from : 18-33-33
scat_ratio 1, (2 inverted) = 1.435, 1.435
Rratio = 0.013 / 0.005 = 2.584


{'pd1': (1.85, 84.0), 'pd2': (1.705, 82.4)}
Accessing cached results from : 18-34-17
Accessing cached results from : 18-35-01
scat_ratio 1, (2 inverted) = 1.284, 1.234
Rratio = 0.012 / 0.012 = 1.023


{'pd1': (1.85, 84.0), 'pd2': (1.705, 80.8)}
Accessing cached results from : 18-35-45
Accessing cached results from : 18-36-37
scat_ratio 1, (2 inverted) = 1.573, 1.257
Rratio = 0.014 / 0.006 = 2.245


{'pd1': (1.85, 84.0), 'pd2': (1.705, 86.4)}
Accessing cached results from : 18-37-28
Accessing cached results from : 18-38-22
scat_ratio 1, (2 inverted) = 0.889, 0.855
Rratio = 0.013 / 0.006 = 2.128


{'pd1': (1.85, 84.0), 'pd2': (1.705, 85.6)}
Accessing cached results from : 18-39-14
Accessing cached results from : 18-40-07
scat_ratio 1, (2 inverted) = 0.933, 0.855
Rratio = 0.012 / 0.008 = 1.473


{'pd1': (1.85, 84.0), 'pd2': (1.705, 80.0)}
Accessing cached results from : 18-41-02
Accessing cached results from : 18-41-55
scat_ratio 1, (2 inverted) = 1.809, 1.670
Rratio = 0.012 / 0.003 = 3.440


{'pd1': (1.85, 84.0), 'pd2': (1.705, 84.0)}
Accessing cached results from : 18-42-50
Accessing cached results from : 18-43-45
scat_ratio 1, (2 inverted) = 1.035, 1.021
Rratio = 0.013 / 0.012 = 1.036


{'pd1': (1.85, 84.0), 'pd2': (1.705, 81.6)}
Accessing cached results from : 18-44-38
Accessing cached results from : 18-45-32
scat_ratio 1, (2 inverted) = 1.419, 1.344
Rratio = 0.011 / 0.011 = 0.932


{'pd1': (1.85, 84.0), 'pd2': (1.705, 83.2)}
Accessing cached results from : 18-46-25
Accessing cached results from : 18-47-18
scat_ratio 1, (2 inverted) = 1.115, 1.099
Rratio = 0.013 / 0.013 = 0.946


{'pd1': (1.85, 84.0), 'pd2': (1.705, 88.0)}
Accessing cached results from : 18-48-12
Accessing cached results from : 18-49-06
scat_ratio 1, (2 inverted) = 1.032, -41.446
Rratio = 0.012 / -0.000 = -67.052


{'pd1': (1.85, 84.0), 'pd2': (1.705, 87.2)}
Accessing cached results from : 18-50-01
Accessing cached results from : 18-50-54
scat_ratio 1, (2 inverted) = 0.894, 0.770
Rratio = 0.013 / 0.003 = 3.983


{'pd1': (1.85, 84.0), 'pd2': (1.705, 84.8)}
Accessing cached results from : 18-51-46
Accessing cached results from : 18-52-38
scat_ratio 1, (2 inverted) = 0.942, 0.929
Rratio = 0.012 / 0.010 = 1.155


{'pd1': (1.85, 84.0), 'pd2': (0.4, 82.4)}
Accessing cached results from : 18-53-31
Accessing cached results from : 18-54-26
scat_ratio 1, (2 inverted) = 3.368, 3.034
Rratio = 0.012 / 0.002 = 7.017


{'pd1': (1.85, 84.0), 'pd2': (0.4, 80.8)}
Accessing cached results from : 18-55-20
Accessing cached results from : 18-56-14
scat_ratio 1, (2 inverted) = 4.662, 4.456
Rratio = 0.011 / 0.001 = 9.568


{'pd1': (1.85, 84.0), 'pd2': (0.4, 86.4)}
Accessing cached results from : 18-57-09
Accessing cached results from : 18-58-04
scat_ratio 1, (2 inverted) = 1.368, 1.359
Rratio = 0.010 / 0.002 = 5.204


{'pd1': (1.85, 84.0), 'pd2': (0.4, 85.6)}
Accessing cached results from : 18-58-58
Accessing cached results from : 18-59-53
scat_ratio 1, (2 inverted) = 1.753, 1.686
Rratio = 0.013 / 0.002 = 5.900


{'pd1': (1.85, 84.0), 'pd2': (0.4, 80.0)}
Accessing cached results from : 19-00-50
Accessing cached results from : 19-01-45
scat_ratio 1, (2 inverted) = 5.307, 3.835
Rratio = 0.013 / 0.000 = 41.478


{'pd1': (1.85, 84.0), 'pd2': (0.4, 84.0)}
Accessing cached results from : 19-02-37
Accessing cached results from : 19-03-30
scat_ratio 1, (2 inverted) = 2.477, 2.327
Rratio = 0.011 / 0.002 = 4.873


{'pd1': (1.85, 84.0), 'pd2': (0.4, 81.6)}
Accessing cached results from : 19-04-25
Accessing cached results from : 19-05-18
scat_ratio 1, (2 inverted) = 4.012, 3.708
Rratio = 0.013 / 0.001 = 9.530


{'pd1': (1.85, 84.0), 'pd2': (0.4, 83.2)}
Accessing cached results from : 19-06-09
Accessing cached results from : 19-07-03
scat_ratio 1, (2 inverted) = 2.936, 2.696
Rratio = 0.013 / 0.003 = 4.566


{'pd1': (1.85, 84.0), 'pd2': (0.4, 88.0)}
Accessing cached results from : 19-07-58
Accessing cached results from : 19-08-50
scat_ratio 1, (2 inverted) = 1.066, 1.104
Rratio = 0.013 / 0.001 = 16.966


{'pd1': (1.85, 84.0), 'pd2': (0.4, 87.2)}
Accessing cached results from : 19-09-45
Accessing cached results from : 19-10-40
scat_ratio 1, (2 inverted) = 1.175, 1.171
Rratio = 0.013 / 0.001 = 9.722


{'pd1': (1.85, 84.0), 'pd2': (0.4, 84.8)}
Accessing cached results from : 19-11-33
Accessing cached results from : 19-12-26
scat_ratio 1, (2 inverted) = 2.102, 1.934
Rratio = 0.013 / 0.003 = 4.649


{'pd1': (1.85, 84.0), 'pd2': (0.9800000000000001, 82.4)}
Accessing cached results from : 19-13-21
Accessing cached results from : 19-14-14
scat_ratio 1, (2 inverted) = 1.810, 1.787
Rratio = 0.013 / 0.007 = 1.881


{'pd1': (1.85, 84.0), 'pd2': (0.9800000000000001, 80.8)}
Accessing cached results from : 19-15-07
Accessing cached results from : 19-15-58
scat_ratio 1, (2 inverted) = 2.287, 2.321
Rratio = 0.012 / 0.006 = 1.922


{'pd1': (1.85, 84.0), 'pd2': (0.9800000000000001, 86.4)}
Accessing cached results from : 19-16-53
Accessing cached results from : 19-17-45
scat_ratio 1, (2 inverted) = 0.943, 0.918
Rratio = 0.011 / 0.005 = 2.468


{'pd1': (1.85, 84.0), 'pd2': (0.9800000000000001, 85.6)}
Accessing cached results from : 19-18-39
Accessing cached results from : 19-19-32
scat_ratio 1, (2 inverted) = 1.042, 1.027
Rratio = 0.011 / 0.006 = 1.919


{'pd1': (1.85, 84.0), 'pd2': (0.9800000000000001, 80.0)}
Accessing cached results from : 19-20-25
Accessing cached results from : 19-21-18
scat_ratio 1, (2 inverted) = 2.571, 2.109
Rratio = 0.011 / 0.003 = 3.867


{'pd1': (1.85, 84.0), 'pd2': (0.9800000000000001, 84.0)}
Accessing cached results from : 19-22-11
Accessing cached results from : 19-23-06
scat_ratio 1, (2 inverted) = 1.364, 1.310
Rratio = 0.012 / 0.007 = 1.630


{'pd1': (1.85, 84.0), 'pd2': (0.9800000000000001, 81.6)}
Accessing cached results from : 19-23-58
Accessing cached results from : 19-24-50
scat_ratio 1, (2 inverted) = 2.136, 1.904
Rratio = 0.012 / 0.006 = 1.836


{'pd1': (1.85, 84.0), 'pd2': (0.9800000000000001, 83.2)}
Accessing cached results from : 19-25-42
Accessing cached results from : 19-26-32
scat_ratio 1, (2 inverted) = 1.572, 1.489
Rratio = 0.012 / 0.007 = 1.755


{'pd1': (1.85, 84.0), 'pd2': (0.9800000000000001, 88.0)}
Accessing cached results from : 19-27-24
Accessing cached results from : 19-28-17
scat_ratio 1, (2 inverted) = 0.936, 1.069
Rratio = 0.011 / 0.001 = 8.627


{'pd1': (1.85, 84.0), 'pd2': (0.9800000000000001, 87.2)}
Accessing cached results from : 19-29-10
Accessing cached results from : 19-30-04
scat_ratio 1, (2 inverted) = 0.895, 0.895
Rratio = 0.012 / 0.003 = 4.222


{'pd1': (1.85, 84.0), 'pd2': (0.9800000000000001, 84.8)}
Accessing cached results from : 19-30-56
Accessing cached results from : 19-31-49
scat_ratio 1, (2 inverted) = 1.219, 1.155
Rratio = 0.012 / 0.007 = 1.679


{'pd1': (1.85, 84.0), 'pd2': (0.8350000000000001, 82.4)}
Accessing cached results from : 19-32-43
Accessing cached results from : 19-33-39
scat_ratio 1, (2 inverted) = 1.984, 1.834
Rratio = 0.011 / 0.005 = 2.146


{'pd1': (1.85, 84.0), 'pd2': (0.8350000000000001, 80.8)}
Accessing cached results from : 19-34-31
Accessing cached results from : 19-35-25
scat_ratio 1, (2 inverted) = 2.566, 2.419
Rratio = 0.012 / 0.003 = 3.561


{'pd1': (1.85, 84.0), 'pd2': (0.8350000000000001, 86.4)}
Accessing cached results from : 19-36-19
Accessing cached results from : 19-37-13
scat_ratio 1, (2 inverted) = 0.985, 0.991
Rratio = 0.012 / 0.004 = 2.871


{'pd1': (1.85, 84.0), 'pd2': (0.8350000000000001, 85.6)}
Accessing cached results from : 19-38-05
Accessing cached results from : 19-38-59
scat_ratio 1, (2 inverted) = 1.129, 1.088
Rratio = 0.013 / 0.006 = 2.313


{'pd1': (1.85, 84.0), 'pd2': (0.8350000000000001, 80.0)}
Accessing cached results from : 19-39-54
Accessing cached results from : 19-40-47
scat_ratio 1, (2 inverted) = 2.953, 2.673
Rratio = 0.013 / 0.003 = 4.652


{'pd1': (1.85, 84.0), 'pd2': (0.8350000000000001, 84.0)}
Accessing cached results from : 19-41-43
Accessing cached results from : 19-42-38
scat_ratio 1, (2 inverted) = 1.543, 1.515
Rratio = 0.013 / 0.006 = 2.145


{'pd1': (1.85, 84.0), 'pd2': (0.8350000000000001, 81.6)}
Accessing cached results from : 19-43-34
Accessing cached results from : 19-44-27
scat_ratio 1, (2 inverted) = 2.296, 2.163
Rratio = 0.013 / 0.007 = 2.013


{'pd1': (1.85, 84.0), 'pd2': (0.8350000000000001, 83.2)}
Accessing cached results from : 19-45-18
Accessing cached results from : 19-46-12
scat_ratio 1, (2 inverted) = 1.747, 1.731
Rratio = 0.013 / 0.006 = 2.219


{'pd1': (1.85, 84.0), 'pd2': (0.8350000000000001, 88.0)}
Accessing cached results from : 19-47-08
Accessing cached results from : 19-48-02
scat_ratio 1, (2 inverted) = 0.925, 1.049
Rratio = 0.011 / -0.001 = -9.977


{'pd1': (1.85, 84.0), 'pd2': (0.8350000000000001, 87.2)}
Accessing cached results from : 19-48-55
Accessing cached results from : 19-49-51
scat_ratio 1, (2 inverted) = 0.915, 0.917
Rratio = 0.012 / 0.002 = 4.769


{'pd1': (1.85, 84.0), 'pd2': (0.8350000000000001, 84.8)}
Accessing cached results from : 19-50-43
Accessing cached results from : 19-51-37
scat_ratio 1, (2 inverted) = 1.283, 1.256
Rratio = 0.011 / 0.006 = 1.774


100%|██████████| 121/121 [00:00<00:00, 324.84it/s]
{'pd1': (1.85, 84.0), 'pd2': (1.415, 82.4)}
Accessing cached results from : 19-52-32
Accessing cached results from : 19-53-26
scat_ratio 1, (2 inverted) = 1.391, 1.401
Rratio = 0.011 / 0.010 = 1.071


{'pd1': (1.85, 84.0), 'pd2': (1.415, 80.8)}
Accessing cached results from : 19-54-20
Accessing cached results from : 19-55-13
scat_ratio 1, (2 inverted) = 1.768, 1.668
Rratio = 0.011 / 0.006 = 1.792


{'pd1': (1.85, 84.0), 'pd2': (1.415, 86.4)}
Accessing cached results from : 19-56-07
Accessing cached results from : 19-57-02
scat_ratio 1, (2 inverted) = 0.374, 0.882
Rratio = 0.011 / 0.005 = 2.045


{'pd1': (1.85, 84.0), 'pd2': (1.415, 85.6)}
Accessing cached results from : 19-57-56
Accessing cached results from : 19-58-49
scat_ratio 1, (2 inverted) = 0.912, 0.904
Rratio = 0.011 / 0.008 = 1.399


{'pd1': (1.85, 84.0), 'pd2': (1.415, 80.0)}
Accessing cached results from : 19-59-43
Accessing cached results from : 20-00-35
scat_ratio 1, (2 inverted) = 2.037, 1.911
Rratio = 0.011 / 0.003 = 3.274


{'pd1': (1.85, 84.0), 'pd2': (1.415, 84.0)}
Accessing cached results from : 20-01-27
Accessing cached results from : 20-02-23
scat_ratio 1, (2 inverted) = 1.132, 1.076
Rratio = 0.011 / 0.010 = 1.090


{'pd1': (1.85, 84.0), 'pd2': (1.415, 81.6)}
Accessing cached results from : 20-03-16
Accessing cached results from : 20-04-08
scat_ratio 1, (2 inverted) = 1.577, 1.502
Rratio = 0.011 / 0.005 = 1.996


{'pd1': (1.85, 84.0), 'pd2': (1.415, 83.2)}
Accessing cached results from : 20-05-01
Accessing cached results from : 20-05-44
scat_ratio 1, (2 inverted) = 1.226, 1.195
Rratio = 0.011 / 0.010 = 1.025


{'pd1': (1.85, 84.0), 'pd2': (1.415, 88.0)}
Accessing cached results from : 20-06-28
Accessing cached results from : 20-07-12
scat_ratio 1, (2 inverted) = 1.581, 0.571
Rratio = 0.011 / -0.000 = -79.686


{'pd1': (1.85, 84.0), 'pd2': (1.415, 87.2)}
Accessing cached results from : 20-07-55
Accessing cached results from : 20-08-39
scat_ratio 1, (2 inverted) = 0.526, 0.898
Rratio = 0.011 / 0.003 = 3.555


{'pd1': (1.85, 84.0), 'pd2': (1.415, 84.8)}
Accessing cached results from : 20-09-22
Accessing cached results from : 20-10-06
scat_ratio 1, (2 inverted) = 1.005, 0.987
Rratio = 0.011 / 0.009 = 1.208


{'pd1': (1.85, 84.0), 'pd2': (0.545, 82.4)}
Accessing cached results from : 20-10-49
Accessing cached results from : 20-11-33
scat_ratio 1, (2 inverted) = 2.585, 2.419
Rratio = 0.010 / 0.002 = 5.209


{'pd1': (1.85, 84.0), 'pd2': (0.545, 80.8)}
Accessing cached results from : 20-12-17
Accessing cached results from : 20-13-01
scat_ratio 1, (2 inverted) = 3.428, 3.152
Rratio = 0.012 / 0.003 = 3.875


{'pd1': (1.85, 84.0), 'pd2': (0.545, 86.4)}
Accessing cached results from : 20-13-44
Accessing cached results from : 20-14-28
scat_ratio 1, (2 inverted) = 1.182, 1.171
Rratio = 0.012 / 0.003 = 4.254


{'pd1': (1.85, 84.0), 'pd2': (0.545, 85.6)}
Accessing cached results from : 20-15-12
Accessing cached results from : 20-15-55
scat_ratio 1, (2 inverted) = 1.398, 1.371
Rratio = 0.012 / 0.003 = 3.554


{'pd1': (1.85, 84.0), 'pd2': (0.545, 80.0)}
Accessing cached results from : 20-16-39
Accessing cached results from : 20-17-24
scat_ratio 1, (2 inverted) = 4.047, 3.348
Rratio = 0.012 / 0.002 = 7.187


{'pd1': (1.85, 84.0), 'pd2': (0.545, 84.0)}
Accessing cached results from : 20-18-07
Accessing cached results from : 20-18-51
scat_ratio 1, (2 inverted) = 1.996, 1.892
Rratio = 0.012 / 0.004 = 3.268


{'pd1': (1.85, 84.0), 'pd2': (0.545, 81.6)}
Accessing cached results from : 20-19-35
Accessing cached results from : 20-20-19
scat_ratio 1, (2 inverted) = 2.968, 2.747
Rratio = 0.012 / 0.003 = 4.301


{'pd1': (1.85, 84.0), 'pd2': (0.545, 83.2)}
Accessing cached results from : 20-21-02
Accessing cached results from : 20-21-47
scat_ratio 1, (2 inverted) = 2.238, 2.160
Rratio = 0.012 / 0.003 = 3.724


{'pd1': (1.85, 84.0), 'pd2': (0.545, 88.0)}
Accessing cached results from : 20-22-32
Accessing cached results from : 20-23-18
scat_ratio 1, (2 inverted) = 0.964, 1.044
Rratio = 0.012 / 0.001 = 16.911


{'pd1': (1.85, 84.0), 'pd2': (0.545, 87.2)}
Accessing cached results from : 20-24-04
Accessing cached results from : 20-24-50
scat_ratio 1, (2 inverted) = 1.019, 1.045
Rratio = 0.011 / 0.002 = 5.263


{'pd1': (1.85, 84.0), 'pd2': (0.545, 84.8)}
Accessing cached results from : 20-25-34
Accessing cached results from : 20-26-20
scat_ratio 1, (2 inverted) = 1.691, 1.630
Rratio = 0.010 / 0.004 = 2.770


{'pd1': (1.85, 84.0), 'pd2': (1.27, 82.4)}
Accessing cached results from : 20-27-05
Accessing cached results from : 20-27-51
scat_ratio 1, (2 inverted) = 1.540, 1.471
Rratio = 0.011 / 0.009 = 1.330


{'pd1': (1.85, 84.0), 'pd2': (1.27, 80.8)}
Accessing cached results from : 20-28-39
Accessing cached results from : 20-29-29
scat_ratio 1, (2 inverted) = 1.899, 1.822
Rratio = 0.011 / 0.003 = 3.943


{'pd1': (1.85, 84.0), 'pd2': (1.27, 86.4)}
Accessing cached results from : 20-30-22
Accessing cached results from : 20-31-20
scat_ratio 1, (2 inverted) = 0.882, 0.857
Rratio = 0.011 / 0.005 = 2.227


{'pd1': (1.85, 84.0), 'pd2': (1.27, 85.6)}
Accessing cached results from : 20-32-12
Accessing cached results from : 20-33-07
scat_ratio 1, (2 inverted) = 0.939, 0.926
Rratio = 0.009 / 0.007 = 1.339


{'pd1': (1.85, 84.0), 'pd2': (1.27, 80.0)}
Accessing cached results from : 20-33-57
Accessing cached results from : 20-34-48
scat_ratio 1, (2 inverted) = 2.196, 2.159
Rratio = 0.011 / 0.003 = 4.031


{'pd1': (1.85, 84.0), 'pd2': (1.27, 84.0)}
Accessing cached results from : 20-35-41
Accessing cached results from : 20-36-35
scat_ratio 1, (2 inverted) = 1.222, 1.172
Rratio = 0.010 / 0.008 = 1.306


{'pd1': (1.85, 84.0), 'pd2': (1.27, 81.6)}
Accessing cached results from : 20-37-26
Accessing cached results from : 20-38-18
scat_ratio 1, (2 inverted) = 1.707, 1.609
Rratio = 0.011 / 0.010 = 1.063


{'pd1': (1.85, 84.0), 'pd2': (1.27, 83.2)}
Accessing cached results from : 20-39-08
Accessing cached results from : 20-39-58
scat_ratio 1, (2 inverted) = 1.292, 1.254
Rratio = 0.010 / 0.010 = 1.092


{'pd1': (1.85, 84.0), 'pd2': (1.27, 88.0)}
Accessing cached results from : 20-40-50
Accessing cached results from : 20-41-42
scat_ratio 1, (2 inverted) = 0.914, 0.330
Rratio = 0.011 / 0.013 = 0.809


{'pd1': (1.85, 84.0), 'pd2': (1.27, 87.2)}
Accessing cached results from : 20-42-28
Accessing cached results from : 20-43-15
scat_ratio 1, (2 inverted) = 0.882, 0.879
Rratio = 0.011 / 0.003 = 3.409


{'pd1': (1.85, 84.0), 'pd2': (1.27, 84.8)}
Accessing cached results from : 20-44-02
Accessing cached results from : 20-44-50
scat_ratio 1, (2 inverted) = 1.045, 1.050
Rratio = 0.012 / 0.009 = 1.322


{'pd1': (1.85, 84.0), 'pd2': (1.56, 82.4)}
Accessing cached results from : 20-45-40
Accessing cached results from : 20-46-29
scat_ratio 1, (2 inverted) = 1.333, 1.295
Rratio = 0.012 / 0.011 = 1.111


{'pd1': (1.85, 84.0), 'pd2': (1.56, 80.8)}
Accessing cached results from : 20-47-19
Accessing cached results from : 20-48-09
scat_ratio 1, (2 inverted) = 1.675, 1.603
Rratio = 0.012 / 0.004 = 2.848


{'pd1': (1.85, 84.0), 'pd2': (1.56, 86.4)}
Accessing cached results from : 20-49-00
Accessing cached results from : 20-49-52
scat_ratio 1, (2 inverted) = 0.861, 0.841
Rratio = 0.012 / 0.006 = 2.133


{'pd1': (1.85, 84.0), 'pd2': (1.56, 85.6)}
Accessing cached results from : 20-50-43
Accessing cached results from : 20-51-33
scat_ratio 1, (2 inverted) = 0.902, 0.359
Rratio = 0.012 / 0.008 = 1.462


{'pd1': (1.85, 84.0), 'pd2': (1.56, 80.0)}
Accessing cached results from : 20-52-23
Accessing cached results from : 20-53-13
scat_ratio 1, (2 inverted) = 1.905, 1.832
Rratio = 0.013 / 0.003 = 4.586


{'pd1': (1.85, 84.0), 'pd2': (1.56, 84.0)}
Accessing cached results from : 20-54-03
Accessing cached results from : 20-54-56
scat_ratio 1, (2 inverted) = 1.081, 1.022
Rratio = 0.012 / 0.011 = 1.119


{'pd1': (1.85, 84.0), 'pd2': (1.56, 81.6)}
Accessing cached results from : 20-55-47
Accessing cached results from : 20-56-40
scat_ratio 1, (2 inverted) = 1.477, 1.428
Rratio = 0.011 / 0.007 = 1.610


{'pd1': (1.85, 84.0), 'pd2': (1.56, 83.2)}
Accessing cached results from : 20-57-31
Accessing cached results from : 20-58-23
scat_ratio 1, (2 inverted) = 1.192, 1.149
Rratio = 0.011 / 0.011 = 1.001


{'pd1': (1.85, 84.0), 'pd2': (1.56, 88.0)}
Accessing cached results from : 20-59-12
Accessing cached results from : 20-59-57
scat_ratio 1, (2 inverted) = 4.087, 0.305
Rratio = 0.011 / 0.000 = 42.296


{'pd1': (1.85, 84.0), 'pd2': (1.56, 87.2)}
Accessing cached results from : 21-00-42
Accessing cached results from : 21-01-27
scat_ratio 1, (2 inverted) = 0.672, 0.792
Rratio = 0.011 / 0.003 = 3.802


{'pd1': (1.85, 84.0), 'pd2': (1.56, 84.8)}
Accessing cached results from : 21-02-12
Accessing cached results from : 21-02-56
scat_ratio 1, (2 inverted) = 0.980, 0.974
Rratio = 0.010 / 0.009 = 1.095


{'pd1': (1.85, 84.0), 'pd2': (1.85, 82.4)}
Accessing cached results from : 21-03-41
Accessing cached results from : 21-04-25
scat_ratio 1, (2 inverted) = 1.229, 1.163
Rratio = 0.011 / 0.009 = 1.162


{'pd1': (1.85, 84.0), 'pd2': (1.85, 80.8)}
Accessing cached results from : 21-05-09
Accessing cached results from : 21-05-53
scat_ratio 1, (2 inverted) = 1.532, 0.903
Rratio = 0.010 / 0.004 = 2.476


{'pd1': (1.85, 84.0), 'pd2': (1.85, 86.4)}
Accessing cached results from : 21-06-37
Accessing cached results from : 21-07-20
scat_ratio 1, (2 inverted) = 0.865, 0.878
Rratio = 0.011 / 0.005 = 2.147


{'pd1': (1.85, 84.0), 'pd2': (1.85, 85.6)}
Accessing cached results from : 21-08-04
Accessing cached results from : 21-08-57
scat_ratio 1, (2 inverted) = 0.913, 0.862
Rratio = 0.010 / 0.008 = 1.356


{'pd1': (1.85, 84.0), 'pd2': (1.85, 80.0)}
Accessing cached results from : 21-09-50
Accessing cached results from : 21-10-43
scat_ratio 1, (2 inverted) = 1.760, 0.904
Rratio = 0.011 / 0.001 = 9.706


{'pd1': (1.85, 84.0), 'pd2': (1.85, 84.0)}
Accessing cached results from : 21-11-36
Accessing cached results from : 21-12-29
scat_ratio 1, (2 inverted) = 1.019, 1.003
Rratio = 0.011 / 0.010 = 1.080


{'pd1': (1.85, 84.0), 'pd2': (1.85, 81.6)}
Accessing cached results from : 21-13-13
Accessing cached results from : 21-13-57
scat_ratio 1, (2 inverted) = 1.345, -0.131
Rratio = 0.011 / 0.008 = 1.386


{'pd1': (1.85, 84.0), 'pd2': (1.85, 83.2)}
Accessing cached results from : 21-14-41
Accessing cached results from : 21-15-24
scat_ratio 1, (2 inverted) = 1.095, 1.065
Rratio = 0.012 / 0.012 = 1.000


{'pd1': (1.85, 84.0), 'pd2': (1.85, 88.0)}
Accessing cached results from : 21-16-08
Accessing cached results from : 21-16-52
scat_ratio 1, (2 inverted) = 15.371, -0.022
Rratio = 0.011 / 0.001 = 12.196


{'pd1': (1.85, 84.0), 'pd2': (1.85, 87.2)}
Accessing cached results from : 21-17-36
Accessing cached results from : 21-18-19
scat_ratio 1, (2 inverted) = 0.917, 0.864
Rratio = 0.012 / 0.004 = 3.060


{'pd1': (1.85, 84.0), 'pd2': (1.85, 84.8)}
Accessing cached results from : 21-19-03
Accessing cached results from : 21-19-47
scat_ratio 1, (2 inverted) = 0.934, 0.930
Rratio = 0.013 / 0.010 = 1.278


<ipython-input-67-ffdbf096cf32>:3: FutureWarning: In a future version of pandas all arguments of DataFrame.pivot will be keyword-only.
  pivot_table = scat_df.pivot('pa2', 'pd2', 'depth_ratio')
In [ ]:
import os
import sys
from functools import partial
sys.path.append(os.path.join(os.getcwd(), '..')) #adds directory below as valid path
from  datetime import datetime, timedelta
dateformat = "%H-%M-%S"
from collections import deque
import traceback
from multiprocessing import Pool
from tqdm import tqdm

import scipy.constants as spc
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd

plt.rcParams['axes.grid'] = True
plt.rcParams['grid.linestyle'] = '--'

from MT_class_PID_new import MTdataHost
from global_folder.myplotsty import *
from global_folder.my_helpers import *

PUMP_FREQUENCY = 384228.6
REPUMP_FREQUENCY = 384228.6 + 6.56
SAMPLE_RATE = 2000
FREQVSVOLT = 221.0 
FREQVSCURR = 1.13

# TODO: find a better place for this
EXP_FOLDER =r'C:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\CATMeasurements'
MEASURE_FOLDER = os.path.join(EXP_FOLDER, 'testPArun16')
WDATA_FOLDER =os.path.join(MEASURE_FOLDER, 'testPArun16.csv')

# TODO: maybe make a run analysis class out of this?
def dump():
	fig, ax = plt.subplots()
	plot_results(ax, df, max_freq= 384219., fmt='o', mfc='red', save_folder=MEASURE_FOLDER)
	plt.savefig(os.path.join(MEASURE_FOLDER, 'ratio_vs_freq.png'))

	
	collect_plots(MEASURE_FOLDER, os.path.join(MEASURE_FOLDER, 'collected_plots'), 'deloadPhase.png')
 
	#*-----------------------
	#* SINGLE RUN
 	#*----------------------- 
  
	MEASURE_FOLDER = os.path.join(EXP_FOLDER, 'testPArun9')
	df = get_data_frame(MEASURE_FOLDER)
	df.dropna(inplace=True)
	#freqs = plot_results(df, 384201., save_folder=MEASURE_FOLDER)
 
	data = df.dropna()
	freqs = ((384201-PUMP_FREQUENCY)-(data['tempV']-df['tempV'].min())*FREQVSVOLT- (data['currV']-df['currV'].min())*FREQVSCURR)
	fig, ax = plt.subplots()
	plot_spline_fit(ax=ax, x=freqs, y=data['ratio'], yerr=data['ratioErr'], 
				 s=0.1, save_folder=MEASURE_FOLDER, 
				 mfc='red', color='black', 
				 title='Trap Depth = 1.99 K')
 
	# *-----------------------
	# * MULTIPLE RUN COMPARISON
 	# *-----------------------
	folders = [os.path.join(EXP_FOLDER, path ) for path in ['testPARun11', 'testPARun12', 'testPARun13', 'testPARun14']]
	dfs = [get_data_frame(measure_folder, cache_all=True) for measure_folder in folders]

	colors = ['red', 'dodgerblue', 'green', 'grey']
	max_freqs = [384178.881, 384178.593,384179.068, 384184.731]
	#max_freqs=[384178.599, 384179.091, 384184.733]

	zipped_data = list(zip(dfs, max_freqs))
	fig, ax = plt.subplots()
	for i, (df, max_freq)  in enumerate(zipped_data[:3]):
		data = df.dropna()
		freqs = ((max_freq-PUMP_FREQUENCY)-(data['tempV']-data['tempV'].min())*FREQVSVOLT- (data['currV']-data['currV'].min())*FREQVSCURR)
		color = colors[i]
		ax=plot_spline_fit(ax, x=freqs, y=data['ratio'], scolor=color, mfc=color,color=color, s=0.02, ms=5)

	#*-----------------------
	#* PARSING WAVEMETER DATA
 	#*-----------------------

	MEASURE_FOLDER = os.path.join(EXP_FOLDER, 'testPArun14')
	WDATA_FOLDER =os.path.join(MEASURE_FOLDER, 'testPArun14.csv')
	freq_data, max_freq, min_freq = add_wavemeter_data('', WDATA_FOLDER)
	data = freq_data[:]
	levels = staircase_fit(data)

	data = get_data_frame(MEASURE_FOLDER)
	data.dropna(inplace=True)
	freqs = ((max_freq)-(data['tempV']-data['tempV'].min())*FREQVSVOLT- (data['currV']-data['currV'].min())*FREQVSCURR)
	plt.plot(freqs)
 
	#*-----------------------
	#* GETTING DEPTH_RATIO DATAFRAME
 	#*-----------------------
	MEASURE_FOLDER = r'C:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\CATMeasurements\relScatRate'
	depth_ratios_df = get_rel_scattering_df(MEASURE_FOLDER)
	df_slice = depth_ratios_df[(depth_ratios_df['pa1']==1.85) & (depth_ratios_df['pd1']==84) & (depth_ratios_df['pd2'] == 84)]
	x = df_slice['pa2']
	y = df_slice['depth_ratio']
	plt.plot(x,y, 'o')

	#*-----------------------
	#* MEGA_RUN
 	#*-----------------------	
	MEASURE_FOLDER = os.path.join(EXP_FOLDER, 'testPARunMega')
	df = get_data_frame(MEASURE_FOLDER)
	df.dropna(inplace=True)

	df_grouped = df.groupby(by='pump_reference')
	min_ratios = df_grouped['ratio'].min()

	groups = dict(list(df_grouped))
	dfs = [df for df in groups.values()]
 
	max_freqs = [384182.5]*15
	#max_freqs=[384178.599, 384179.091, 384184.733]
	zipped_data = list(zip(dfs, max_freqs))
	fig, ax = plt.subplots()
	for i, (df, max_freq)  in enumerate(zipped_data[:]):
		data = df.dropna()
		freqs = ((max_freq-PUMP_FREQUENCY)-(data['tempV']-data['tempV'].min())*FREQVSVOLT- (data['currV']-data['currV'].min())*FREQVSCURR)
		ax=plot_spline_fit(ax, x=freqs, y=data['ratio'], yerr=data['ratioErr'],scolor=f'C{i}', mfc=f'C{i}',color=f'C{i}', s=0.0, ms=5, figsize=(10, 10), label=f"Pump Amplituide = { df.iloc[10]['pump_reference'] :.2f}", linewidth=2.5)

	plt.legend()

	plt.savefig(os.path.join(MEASURE_FOLDER, 'lossFeatures.png'))
	#*-----------------------
	#* MULTIPLE MEGARUN
	#*-----------------------
 
	folders = [os.path.join(EXP_FOLDER, path ) for path in ['testPArunMega', 'testPArunMega2']]
	dfs_mega = [get_data_frame(measure_folder, cache_all=True).dropna() for measure_folder in folders]

	dfs_grouped = [df_mega.groupby(by='pump_reference') for df_mega in dfs_mega]
	min_ratios = [df_grouped['ratio'].min() for df_grouped in dfs_grouped]

	groupss = [dict(list(df_grouped)) for df_grouped in dfs_grouped]
	dfs = [ [df for df in groups.values()] for groups in groupss]
 
	for row in dfs:
		x = [df['pump_reference'].mean() for df in row]
		y = [(df['ratio'].max() - df['ratio'].min())/df['motSS'].std() for df in row]
		plt.plot( x, y ,'-o', label=fr"$\delta$ = {180 - 2*row[0]['pump_AOM_freq'].mean()} MHz")
		plt.xlabel('Pump Amplitude')
		plt.ylabel(r'SNR $ = \frac{V_{ss, off} - V_{ss, on}}{\sigma_{V,off}}$ ')
	plt.legend()

def freq_misc():
	WDATA_FOLDER = r'C:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\CATMeasurements\CATcurrTestrun3.csv'
	freq_data = add_wavemeter_data('', WDATA_FOLDER)
	levels = staircase_fit(freq_data[0], peak_height=0.2, distance=50, data_offset=1, window_size=1) 

	plt.close()
 
	x = np.linspace(0, 4.9, 25)
	y = levels
 
	plt.plot(levels, '-o')
	plt.title('Levels plot')
	
	m, b, fit_line = my_linear_fit(x, y)
def save_fit_results(run_path, plot=False):
	filename = os.path.join(run_path, 'data.csv')
	bkfilename = os.path.join(run_path, 'data_oldPD.csv')
	settingsname = os.path.join(run_path, 'Settings.txt')
	
	dataHost = MTdataHost(SAMPLE_RATE)
	dataHost.loadCATdata(fileName=filename, settingsName=settingsname)
	dataHost.CATbackgroundData(bkfilename)
	
	dataHost.setAllCAT(0.002)
	resultDict = dataHost.getResults(run_path, store=True)
 
	if plot:
		dataHost.storeFits(run_path, combined=True, separate=True)
  
	return resultDict, dataHost.settings
		
def get_timestamp(run_path):
	timestamp = datetime.strptime(os.path.split(run_path)[-1].split('_')[0], dateformat)
	return timestamp

def extract_fit(run_path, plot=True, cache_failed=True, cache_all=True):
	"""Gather relevant data from each measurement run

	Args:
		run_path : absolute path to the run directory
		plot (bool, optional): plot fits. Defaults to True.
		cache_failed (bool, optional): Cache failed fits. If false, refit. Doesn't refit non-failed fits. Defaults to True.
		cache_all (bool, optional): If false, ignore any cached fit_results. Defaults to True.

	Returns:
		a 3-tuple (fit_results, settings, timestamp)
	"""
	fit_results, settings, timestamp = {}, {}, None
	
	if not os.path.isdir(run_path):
		return fit_results, settings, timestamp  # directory is not a run directory

	try:
		timestamp = get_timestamp(run_path)
  
  	# TODO: specify which error to catch
	except Exception as e:
		print("Error extracting timestamp from: ", run_path)
		print(traceback.format_exc())
	
	MAT_fit_cache_path = os.path.join(run_path, 'resultDict.txt')
 
	if not os.path.exists(MAT_fit_cache_path) or not cache_all:
		
		try: 
			fit_results, settings = save_fit_results(run_path, plot=plot)
		except Exception as e:
			print(traceback.format_exc())
			print("Fitting ERROR at ", os.path.basename(run_path), '\n')

			with open(MAT_fit_cache_path, 'w') as f:
				f.write(str('MAT fit failed'))
		
	else:
		print("Accessing cached results from :", os.path.basename(run_path))
  
		fit_results = open(MAT_fit_cache_path, 'r').read()

		if fit_results == 'MAT fit failed':
			if not cache_failed:
				# fit regardless of cached result
				try: 
					fit_results, settings = save_fit_results(run_path, plot=plot)
				except Exception as e:
					print(traceback.format_exc())
					print("Fitting ERROR at ", os.path.basename(run_path), '\n')
	
					with open(MAT_fit_cache_path, 'w') as f:
						f.write(str('MAT fit failed'))	
			else:
				print("Failed fit at :", os.path.basename(run_path))
				fit_results = {}

		else:
			fit_results = eval(open(MAT_fit_cache_path, 'r').read())
   
			settingsname = os.path.join(run_path, 'Settings.txt')
			settings = eval(open(settingsname, 'r').read())
   
	return fit_results, settings, timestamp



def get_row(run_path, **kwargs):
			
   fit_results, settings, timestamp = extract_fit(run_path, **kwargs)
   row = {**fit_results, **settings, **{'timestamp':timestamp}}
   
   return row

   
def get_data_frame(data_dir, parallel=True, in_process_run=False, **kwargs):
   
	run_path_arr = []
	rows = []
	
	for relative_path in os.listdir(data_dir):
		run_path_arr.append(os.path.join(data_dir, relative_path))
  
	if in_process_run:
		run_path_arr.pop()

	run_path_arr = sorted(run_path_arr)
	
	if parallel:
		with Pool(4) as p:
			rows = list(tqdm(p.imap(partial(get_row, **kwargs), run_path_arr), total=len(run_path_arr)))
	
	else:
		for run_path in tqdm(run_path_arr):
		   rows.append(get_row(run_path, **kwargs))

	return pd.DataFrame.from_dict(rows)

def add_wavemeter_data(df, wmeter_csv_path, window_size=100, num_rows=50):


	"""Extract unique frequnecy values from wavemeter data
	Returns:
		unique_levels (list): unique frequency values in wavemeter data
	"""
 
	# TODO: modify dataframe in place with frequency data
 
	wdata = pd.read_csv(wmeter_csv_path, skiprows=2)
	wdata.dropna(inplace=True)
	freq_data = np.array(wdata.iloc[:, 0])
	try:
		freq_data = np.array([float(item) for item in freq_data if item.replace('.','').isdigit()])
	except Exception as e:
		print(e)
 
	max_freq = freq_data.max()
	min_freq = freq_data.min()

	return freq_data, max_freq, min_freq

def plot_results(ax, dfs, max_freq, min_freq=0.0, mfc='red', fmt='o', ms=5, save_folder=False, xscale=1.0, yscale=1.0, **kwargs):
	FREQVSVOLT = 221.0 
	FREQVSCURR = 1.13
	
	if not type(dfs) == list:
		freqs = ((max_freq-PUMP_FREQUENCY)-(dfs.dropna()['tempV']-dfs.dropna()['tempV'].min())*FREQVSVOLT- (dfs.dropna()['currV']-dfs.dropna()['currV'].min())*FREQVSCURR)*xscale
		dfs=[dfs]
  
	plt.gcf().set_dpi(300)
	
	for df in dfs:
		df = df.dropna()
		ax.errorbar(freqs, 
			   df['ratio']*yscale,
			   yerr=df['ratioErr'],
			   fmt=fmt, mfc=mfc, color='black', ms=ms, **kwargs)
		ax.set_ylabel(r'$\mathbf{\frac{V_{ss, cat}}{V_{ss}}} $ ', **labeldict)
		ax.set_xlabel(r'$\Delta $ (GHz)', **labeldict)
	
	if save_folder:
		plt.savefig(os.path.join(save_folder, 'ratio_vs_freq.png'))
	
	return freqs, ax
  
	#return plt.gca(), plt.gcf()
	#plt.show()

def plot_spline_fit(ax, x, y, s=1, yerr=None, color='black', scolor='black',figsize=(12,5), save_folder=None, title='',alpha=0.5,dpi=200, label='plot',**kwargs):
	from scipy.interpolate import splev, splrep
	xnew = np.linspace(min(x), max(x), 3*len(x) )

	y = [b for a,b in sorted(zip(x,y), key=lambda pair: pair[0])]
	if yerr is not None:
		yerr = [b for a,b in sorted(zip(x,yerr), key=lambda pair: pair[0])]
 
	x = sorted(x)

	spl = splrep(x, y, s=s)
	ynew = splev(xnew, spl)

	
	plt.gcf().set_dpi(dpi)
	plt.gcf().set_size_inches(figsize)
	
	if yerr is not None:
		ax.errorbar(x, y, yerr=yerr, fmt='o', **kwargs)
	else:
		ax.plot(x,y, 'o', **kwargs)
	ax.plot(xnew, ynew, '-', color=scolor, alpha=alpha, label=label, **kwargs)
 
	ax.set_ylabel(r'$\mathbf{\frac{V_{ss, cat}}{V_{ss}}} $ ', **labeldict)
	ax.set_xlabel(r'$\Delta $ (GHz)', **labeldict)
 
	ax.set_title(title, **titledict)
	if save_folder:
		plt.savefig(os.path.join(save_folder, 'spline_ratio_vs_freq.png'))
	
	return ax
 
def plot_polyfit(x_data, y_data, spline_degree):
	
	coefficients = np.polyfit(x_data, y_data, spline_degree)

	x_interp = np.linspace(min(x_data), max(x_data), 100)
	y_interp = np.polyval(coefficients, x_interp)

	plt.scatter(x_data, y_data, label='Original Data')
	plt.plot(x_interp, y_interp, label='Polynomial Interpolation (Degree={})'.format(spline_degree))

def collect_plots(source, destination, plot_name):
	print(f'Collecting plots from {os.path.basename(source)}')
	import shutil

	os.makedirs(destination, exist_ok=True)

	plot_files = []
	for root, dirs, files in os.walk(source):
		
		for file in files:
			if file == plot_name:
				plot_files.append(os.path.join(root, file))

	for i, plot_file in enumerate(plot_files, start=0):
		new_filename = f'{i}{plot_name}'
		destination_path = os.path.join(destination, new_filename)
		shutil.copy(plot_file, destination_path)

def create_GIF(images_folder, image_name):
	import imageio
	with imageio.get_writer(os.path.join(images_folder, f'{image_name}movie.gif'), mode='I', duration=0.5) as writer:
		for filename in os.listdir(images_folder):
			if image_name in filename:
				image = imageio.imread(os.path.join(images_folder, filename))
				writer.append_data(image)

def staircase_fit(data, peak_height=0.1, distance=100, data_offset=1, window_size=1, inc_final_peak=True):
	def moving_average(arr, window_size):
		weights = np.ones(window_size) / window_size
		return np.convolve(arr, weights, mode='valid')

	convdata1 = moving_average(data, window_size)
	convdata2 = moving_average(data[data_offset+1:], window_size )
	final = convdata1[:len(convdata2)]-convdata2
	# plt.plot(data)
	# plt.plot(convdata1)
	# plt.plot(convdata2)
	# plt.show()
	# plt.plot(final)

	
	from scipy.signal import find_peaks
	x= final
	peaks, _ = find_peaks(x, height=peak_height, distance=distance)
	peaks = np.insert(peaks, 0, 0)
	levels = []
	plot_arr = []
	for i, peak in enumerate(peaks):
		
		if i < len(peaks) - 1:
			temp = data[ peaks[i]:peaks[i+1] ]
			plot_arr.extend( np.ones_like(temp)*np.mean(temp))
			levels.append(np.mean(temp))
	if inc_final_peak:
		temp = data[peaks[-1]:]
		levels.append(np.mean(temp))
		plot_arr.extend( np.ones_like(temp)*np.mean(temp))
  
	plt.plot(x)
	plt.plot(peaks, x[peaks], "x")
	plt.plot(np.zeros_like(x), "--", color="gray")
	plt.show()
	
	plt.plot(data)
	plt.plot(np.ravel((plot_arr)))
	plt.show()
	plt.close()
	plt.plot(np.array(levels)[np.where(abs(np.diff(levels))>0.05)[0]], 'o', ms=5)
 
	return levels

def load_single_run(run_path):
	filename = os.path.join(run_path, 'data.csv')
	bkfilename = os.path.join(run_path, 'data_oldPD.csv')
	settingsname = os.path.join(run_path, 'Settings.txt')
	
	dh1 = MTdataHost(SAMPLE_RATE)
	dh1.loadCATdata(fileName=filename, settingsName=settingsname)
	
	return dh1
	# *-----------------------
	# *RELATIVE SCATTERING RATE
	# *-----------------------


def get_rel_scattering_df(data_folder):
	depth_ratios_df = []
	listdir = sorted(os.listdir(data_folder))
	try:
		for run_folder1, run_folder2 in tqdm([listdir[i:i+2] for i in range(len(listdir))[::2]]):
			try:
				run_path1 = os.path.join(data_folder, run_folder1)
				run_path2 = os.path.join(data_folder, run_folder2)
				result = {}
				with open(os.path.join(run_path1, 'twoSettings.txt'), 'r') as f:
					settings = f.read() 
					import re

					pattern = r'(\w+)\s*=\s*\(([\d.]+),\s*([\d.]+)\)'

					matches = re.findall(pattern, settings)

					
					for match in matches:
						key = match[0]
						value1 = float(match[1])
						value2 = float(match[2])
						result[key] = (value1, value2)

					#print(result)
				with open(os.path.join(run_path2, 'twoSettings.txt'), 'r') as f:
					pass
					#print(f.readlines())
				
				timestamp = get_timestamp(run_path1)
				fit_results1, fit_results2, fit_results, depth_ratio = get_rel_scattering(run_path1, run_path2)
				
				extracted_values = {
						'pa1': result['pd1'][0],
						'pd1': result['pd1'][1],
						'pa2': result['pd2'][0],
						'pd2': result['pd2'][1],
						'depth_ratio': 1/float(depth_ratio), # ratio between current and std settings
	  					'timestamp': timestamp,
						**fit_results
					}
				depth_ratios_df.append(extracted_values)
				
				print('\n')
			except Exception as e:
					print(traceback.format_exc())
					print(f'Error {e} at {run_folder1, run_folder2}')
	except Exception as e:
		print(f'Error {e}')

	depth_ratios_df = pd.DataFrame(depth_ratios_df)
 
	return depth_ratios_df

def get_rel_scattering(run_path1, run_path2):
	resultDict = {}
	
	resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
	resultDict['scat_ratio1'] = scat_ratio1
	resultDict2, scat_ratio2 = _load_single_run_rel_scat(run_path2, plot=True)
	resultDict['scat_ratio2'] = scat_ratio2
	#print(f"scat_ratio 1, (2 inverted) = {scat_ratio1:.3f}, {1/scat_ratio2:.3f}")
	scat_ratio_avg = (scat_ratio1+1/scat_ratio2)/2
	resultDict['scat_ratio_avg'] = scat_ratio_avg
 
	Rratio = resultDict1['initMOTR']/resultDict2['initMOTR']
	resultDict['Rratio'] = Rratio
	#print(fr"Rratio = {resultDict1['initMOTR']:.3f} / {resultDict2['initMOTR']:.3f} = {Rratio:.3f}")
	depthRatio = np.sqrt(Rratio/scat_ratio_avg)
	
	return resultDict1, resultDict2, resultDict, depthRatio


def _load_single_run_rel_scat(run_path, plot=False, cache_all=True):
	filename = os.path.join(run_path, 'data.csv')
	settingsname = os.path.join(run_path, 'Settings.txt')
	
	MAT_fit_cache_path = os.path.join(run_path, 'resultDict.txt')
	fit_results = {}
	if not os.path.exists(MAT_fit_cache_path) or not cache_all:
		
		try: 
			dh1 = MTdataHost(SAMPLE_RATE)
			dh1.loadCATdata(fileName=filename, settingsName=settingsname)

			#dh1.tBaseline = 1
			dh1.tCATbackground = 1
			dh1.tLoad = 2
			dh1.timeLoad = 30
			dh1.tReload = dh1.tLoad + dh1.timeLoad
			dh1.timeReload = 1

			dh1.setOffset()
			#dh1.tCATbackground = dh1.tReload + dh1.timeReload 
			dh1.tBaseline = dh1.tReload + dh1.timeReload
			#dh1.setCATtiming()
			dh1.setAllCAT(0.002)

			print('FITTINGGGGGGGGGGGG')
			fit_results = dh1.getResults(run_path, store=True)
			if plot:
				dh1.storeFits(run_path, combined=True, separate=False)
		except Exception as e:
			print(traceback.format_exc())
			print("Fitting ERROR at ", os.path.basename(run_path), '\n')

			with open(MAT_fit_cache_path, 'w') as f:
				f.write(str('MAT fit failed'))
		
	else:
		print("Accessing cached results from :", os.path.basename(run_path))

		fit_results = open(MAT_fit_cache_path, 'r').read()

		if fit_results == 'MAT fit failed':
			print("Failed fit at :", os.path.basename(run_path))
			fit_results = {}

		else:
			fit_results = eval(open(MAT_fit_cache_path, 'r').read())


	
	#scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
	scat_ratio = (fit_results['motSS']+fit_results['baseVolt']-(fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))/(fit_results['reloadVolt'])
	fit_results['scat_ratio'] = scat_ratio
 	#scat_ratio = dh1.motSS/(dh1.reloadVolt+dh1.baseVolt - (dh1.CATbackgroundVolt+dh1.noLightBackground))
	
	return fit_results, scat_ratio

def scat_rate(I, delta, gamma=6.065, Is=1.669):
	"""_summary_

	Args:
		I (float): intensity (Mhz)
		delta (float): detuning (Mhz)
		gamma (float, optional): linewidth (Mhz) Defaults to 6.065.
		Is (float, optional): Should be one of 3.576(isotropic), 2.503(pi), 1.669 (sigma+-). Defaults to 1.669.

	Returns:
		_type_: gamma: the scattering rate
	"""
	return gamma*I/(2*Is*(1+I/Is+4*(delta/gamma)**2))

if __name__ == '__main__':
	run_path = r"C:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\CATMeasurements\testPArun9\16-53-10"
	filename = os.path.join(run_path, 'data.csv')
	bkfilename = os.path.join(run_path, 'data_oldPD.csv')
	settingsname = os.path.join(run_path, 'Settings.txt')
	
	dh1 = MTdataHost(SAMPLE_RATE)
	dh1.loadCATdata(fileName=filename, settingsName=settingsname)
	
 	#dh1.CATbackgroundData(bkfilename)
	dh1.setAllCAT(0.002)
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
In [ ]:
import seaborn as sns
scat_df = get_rel_scattering_df(r'C:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\CATMeasurements\relScatRate\TrapDepthMap')
pivot_table = scat_df.pivot('pa2', 'pd2', 'depth_ratio')
sns.heatmap(pivot_table, annot=True, fmt='.2f', cmap='magma')
plt.grid()
  0%|          | 0/121 [00:00<?, ?it/s]<ipython-input-68-33b6e0c766ac>:529: RuntimeWarning: invalid value encountered in sqrt
  depthRatio = np.sqrt(Rratio/scat_ratio_avg)
 29%|██▉       | 35/121 [00:00<00:00, 349.04it/s]
Accessing cached results from : 17-56-41
Accessing cached results from : 17-57-25


Accessing cached results from : 17-58-10
Accessing cached results from : 17-58-54


Accessing cached results from : 17-59-38
Accessing cached results from : 18-00-22


Accessing cached results from : 18-01-06
Accessing cached results from : 18-01-50


Accessing cached results from : 18-02-39
Accessing cached results from : 18-03-31


Accessing cached results from : 18-04-24
Accessing cached results from : 18-05-17


Accessing cached results from : 18-06-11
Accessing cached results from : 18-07-04


Accessing cached results from : 18-07-59
Accessing cached results from : 18-08-51


Accessing cached results from : 18-09-42
Accessing cached results from : 18-10-35


Accessing cached results from : 18-11-29
Accessing cached results from : 18-12-22


Accessing cached results from : 18-13-17
Accessing cached results from : 18-14-10


Accessing cached results from : 18-15-02
Accessing cached results from : 18-15-55


Accessing cached results from : 18-16-49
Accessing cached results from : 18-17-41


Accessing cached results from : 18-18-33
Accessing cached results from : 18-19-25


Accessing cached results from : 18-20-18
Accessing cached results from : 18-21-10


Accessing cached results from : 18-22-04
Accessing cached results from : 18-22-56


Accessing cached results from : 18-23-50
Accessing cached results from : 18-24-46


Accessing cached results from : 18-25-41
Accessing cached results from : 18-26-35


Accessing cached results from : 18-27-30
Accessing cached results from : 18-28-23


Accessing cached results from : 18-29-14
Accessing cached results from : 18-30-07


Accessing cached results from : 18-30-58
Accessing cached results from : 18-31-50


Accessing cached results from : 18-32-43
Accessing cached results from : 18-33-33


Accessing cached results from : 18-34-17
Accessing cached results from : 18-35-01


Accessing cached results from : 18-35-45
Accessing cached results from : 18-36-37


Accessing cached results from : 18-37-28
Accessing cached results from : 18-38-22


Accessing cached results from : 18-39-14
Accessing cached results from : 18-40-07


Accessing cached results from : 18-41-02
Accessing cached results from : 18-41-55


Accessing cached results from : 18-42-50
Accessing cached results from : 18-43-45


Accessing cached results from : 18-44-38
Accessing cached results from : 18-45-32


Accessing cached results from : 18-46-25
Accessing cached results from : 18-47-18


Accessing cached results from : 18-48-12
Accessing cached results from : 18-49-06


Accessing cached results from : 18-50-01
Accessing cached results from : 18-50-54


Accessing cached results from : 18-51-46
Accessing cached results from : 18-52-38


Accessing cached results from : 18-53-31
Accessing cached results from : 18-54-26


Accessing cached results from : 18-55-20
Accessing cached results from : 18-56-14


Accessing cached results from : 18-57-09
Accessing cached results from : 18-58-04


Accessing cached results from : 18-58-58
Accessing cached results from : 18-59-53


Accessing cached results from : 19-00-50
Accessing cached results from : 19-01-45


Accessing cached results from : 19-02-37
Accessing cached results from : 19-03-30


Accessing cached results from : 19-04-25
Accessing cached results from : 19-05-18


Accessing cached results from : 19-06-09
Accessing cached results from : 19-07-03


Accessing cached results from : 19-07-58
Accessing cached results from : 19-08-50


Accessing cached results from : 19-09-45
Accessing cached results from : 19-10-40


Accessing cached results from : 19-11-33
Accessing cached results from : 19-12-26


Accessing cached results from : 19-13-21
Accessing cached results from : 19-14-14


Accessing cached results from : 19-15-07
Accessing cached results from : 19-15-58


Accessing cached results from : 19-16-53
Accessing cached results from : 19-17-45


Accessing cached results from : 19-18-39
Accessing cached results from : 19-19-32


Accessing cached results from : 19-20-25
Accessing cached results from : 19-21-18


Accessing cached results from : 19-22-11
Accessing cached results from : 19-23-06


Accessing cached results from : 19-23-58
Accessing cached results from : 19-24-50


Accessing cached results from : 19-25-42
Accessing cached results from : 19-26-32


Accessing cached results from : 19-27-24
Accessing cached results from : 19-28-17


Accessing cached results from : 19-29-10
Accessing cached results from : 19-30-04


Accessing cached results from : 19-30-56
Accessing cached results from : 19-31-49


Accessing cached results from : 19-32-43
Accessing cached results from : 19-33-39


Accessing cached results from : 19-34-31
Accessing cached results from : 19-35-25


Accessing cached results from : 19-36-19
Accessing cached results from : 19-37-13


Accessing cached results from : 19-38-05
Accessing cached results from : 19-38-59


Accessing cached results from : 19-39-54
Accessing cached results from : 19-40-47


Accessing cached results from : 19-41-43
Accessing cached results from : 19-42-38


Accessing cached results from : 19-43-34
Accessing cached results from : 19-44-27


Accessing cached results from : 19-45-18
Accessing cached results from : 19-46-12


Accessing cached results from : 19-47-08
Accessing cached results from : 19-48-02


Accessing cached results from : 19-48-55
 84%|████████▍ | 102/121 [00:00<00:00, 276.87it/s]
Accessing cached results from : 19-49-51


Accessing cached results from : 19-50-43
Accessing cached results from : 19-51-37


Accessing cached results from : 19-52-32
Accessing cached results from : 19-53-26


Accessing cached results from : 19-54-20
Accessing cached results from : 19-55-13


Accessing cached results from : 19-56-07
Accessing cached results from : 19-57-02


Accessing cached results from : 19-57-56
Accessing cached results from : 19-58-49


Accessing cached results from : 19-59-43
Accessing cached results from : 20-00-35


Accessing cached results from : 20-01-27
Accessing cached results from : 20-02-23


Accessing cached results from : 20-03-16
Accessing cached results from : 20-04-08


Accessing cached results from : 20-05-01
Accessing cached results from : 20-05-44


Accessing cached results from : 20-06-28
Accessing cached results from : 20-07-12


Accessing cached results from : 20-07-55
Accessing cached results from : 20-08-39


Accessing cached results from : 20-09-22
Accessing cached results from : 20-10-06


Accessing cached results from : 20-10-49
Accessing cached results from : 20-11-33


Accessing cached results from : 20-12-17
Accessing cached results from : 20-13-01


Accessing cached results from : 20-13-44
Accessing cached results from : 20-14-28


Accessing cached results from : 20-15-12
Accessing cached results from : 20-15-55


Accessing cached results from : 20-16-39
Accessing cached results from : 20-17-24


Accessing cached results from : 20-18-07
Accessing cached results from : 20-18-51


Accessing cached results from : 20-19-35
Accessing cached results from : 20-20-19


Accessing cached results from : 20-21-02
Accessing cached results from : 20-21-47


Accessing cached results from : 20-22-32
Accessing cached results from : 20-23-18


Accessing cached results from : 20-24-04
Accessing cached results from : 20-24-50


Accessing cached results from : 20-25-34
Accessing cached results from : 20-26-20


Accessing cached results from : 20-27-05
Accessing cached results from : 20-27-51


Accessing cached results from : 20-28-39
Accessing cached results from : 20-29-29


Accessing cached results from : 20-30-22
Accessing cached results from : 20-31-20


Accessing cached results from : 20-32-12
Accessing cached results from : 20-33-07


Accessing cached results from : 20-33-57
Accessing cached results from : 20-34-48


Accessing cached results from : 20-35-41
Accessing cached results from : 20-36-35


Accessing cached results from : 20-37-26
Accessing cached results from : 20-38-18


Accessing cached results from : 20-39-08
Accessing cached results from : 20-39-58


Accessing cached results from : 20-40-50
Accessing cached results from : 20-41-42


Accessing cached results from : 20-42-28
Accessing cached results from : 20-43-15


Accessing cached results from : 20-44-02
Accessing cached results from : 20-44-50


Accessing cached results from : 20-45-40
Accessing cached results from : 20-46-29


Accessing cached results from : 20-47-19
Accessing cached results from : 20-48-09


Accessing cached results from : 20-49-00
Accessing cached results from : 20-49-52


Accessing cached results from : 20-50-43
Accessing cached results from : 20-51-33


Accessing cached results from : 20-52-23
Accessing cached results from : 20-53-13


Accessing cached results from : 20-54-03
Accessing cached results from : 20-54-56


Accessing cached results from : 20-55-47
Accessing cached results from : 20-56-40


Accessing cached results from : 20-57-31
Accessing cached results from : 20-58-23


Accessing cached results from : 20-59-12
Accessing cached results from : 20-59-57


Accessing cached results from : 21-00-42
Accessing cached results from : 21-01-27


Accessing cached results from : 21-02-12
Accessing cached results from : 21-02-56


Accessing cached results from : 21-03-41
Accessing cached results from : 21-04-25


Accessing cached results from : 21-05-09
Accessing cached results from : 21-05-53


Accessing cached results from : 21-06-37
Accessing cached results from : 21-07-20


Accessing cached results from : 21-08-04
Accessing cached results from : 21-08-57


Accessing cached results from : 21-09-50
Accessing cached results from : 21-10-43


100%|██████████| 121/121 [00:00<00:00, 281.09it/s]
<ipython-input-69-ffdbf096cf32>:3: FutureWarning: In a future version of pandas all arguments of DataFrame.pivot will be keyword-only.
  pivot_table = scat_df.pivot('pa2', 'pd2', 'depth_ratio')
Accessing cached results from : 21-11-36
Accessing cached results from : 21-12-29


Accessing cached results from : 21-13-13
Accessing cached results from : 21-13-57


Accessing cached results from : 21-14-41
Accessing cached results from : 21-15-24


Accessing cached results from : 21-16-08
Accessing cached results from : 21-16-52


Accessing cached results from : 21-17-36
Accessing cached results from : 21-18-19


Accessing cached results from : 21-19-03
Accessing cached results from : 21-19-47


In [ ]:
sns.heatmap(pivot_table, annot=True, fmt='.2f', cmap='magma')
plt.grid()
In [ ]:
scat_df[scat_df['depth_ratio'].isna()]
Out[ ]:
pa1 pd1 pa2 pd2 depth_ratio timestamp scat_ratio1 scat_ratio2 scat_ratio_avg Rratio
12 1.85 84.0 0.690 80.8 NaN 1900-01-01 18:16:49 2.957568 0.372832 2.819870 -18.151483
63 1.85 84.0 0.835 88.0 NaN 1900-01-01 19:47:08 0.924823 0.953473 0.986810 -9.977041
74 1.85 84.0 1.415 88.0 NaN 1900-01-01 20:06:28 1.581415 1.751459 1.076184 -79.685872
In [ ]:
import os
import sys
from functools import partial
sys.path.append(os.path.join(os.getcwd(), '..')) #adds directory below as valid path
from  datetime import datetime, timedelta
dateformat = "%H-%M-%S"
from collections import deque
import traceback
from multiprocessing import Pool
from tqdm import tqdm

import scipy.constants as spc
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd

plt.rcParams['axes.grid'] = True
plt.rcParams['grid.linestyle'] = '--'

from MT_class_PID_new import MTdataHost
from global_folder.myplotsty import *
from global_folder.my_helpers import *

PUMP_FREQUENCY = 384228.6
REPUMP_FREQUENCY = 384228.6 + 6.56
SAMPLE_RATE = 2000
FREQVSVOLT = 221.0 
FREQVSCURR = 1.13

# TODO: find a better place for this
EXP_FOLDER =r'C:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\CATMeasurements'
MEASURE_FOLDER = os.path.join(EXP_FOLDER, 'testPArun16')
WDATA_FOLDER =os.path.join(MEASURE_FOLDER, 'testPArun16.csv')

# TODO: maybe make a run analysis class out of this?
def dump():
	fig, ax = plt.subplots()
	plot_results(ax, df, max_freq= 384219., fmt='o', mfc='red', save_folder=MEASURE_FOLDER)
	plt.savefig(os.path.join(MEASURE_FOLDER, 'ratio_vs_freq.png'))

	
	collect_plots(MEASURE_FOLDER, os.path.join(MEASURE_FOLDER, 'collected_plots'), 'deloadPhase.png')
 
	#*-----------------------
	#* SINGLE RUN
 	#*----------------------- 
  
	MEASURE_FOLDER = os.path.join(EXP_FOLDER, 'testPArun9')
	df = get_data_frame(MEASURE_FOLDER)
	df.dropna(inplace=True)
	#freqs = plot_results(df, 384201., save_folder=MEASURE_FOLDER)
 
	data = df.dropna()
	freqs = ((384201-PUMP_FREQUENCY)-(data['tempV']-df['tempV'].min())*FREQVSVOLT- (data['currV']-df['currV'].min())*FREQVSCURR)
	fig, ax = plt.subplots()
	plot_spline_fit(ax=ax, x=freqs, y=data['ratio'], yerr=data['ratioErr'], 
				 s=0.1, save_folder=MEASURE_FOLDER, 
				 mfc='red', color='black', 
				 title='Trap Depth = 1.99 K')
 
	# *-----------------------
	# * MULTIPLE RUN COMPARISON
 	# *-----------------------
	folders = [os.path.join(EXP_FOLDER, path ) for path in ['testPARun11', 'testPARun12', 'testPARun13', 'testPARun14']]
	dfs = [get_data_frame(measure_folder, cache_all=True) for measure_folder in folders]

	colors = ['red', 'dodgerblue', 'green', 'grey']
	max_freqs = [384178.881, 384178.593,384179.068, 384184.731]
	#max_freqs=[384178.599, 384179.091, 384184.733]

	zipped_data = list(zip(dfs, max_freqs))
	fig, ax = plt.subplots()
	for i, (df, max_freq)  in enumerate(zipped_data[:3]):
		data = df.dropna()
		freqs = ((max_freq-PUMP_FREQUENCY)-(data['tempV']-data['tempV'].min())*FREQVSVOLT- (data['currV']-data['currV'].min())*FREQVSCURR)
		color = colors[i]
		ax=plot_spline_fit(ax, x=freqs, y=data['ratio'], scolor=color, mfc=color,color=color, s=0.02, ms=5)

	#*-----------------------
	#* PARSING WAVEMETER DATA
 	#*-----------------------

	MEASURE_FOLDER = os.path.join(EXP_FOLDER, 'testPArun14')
	WDATA_FOLDER =os.path.join(MEASURE_FOLDER, 'testPArun14.csv')
	freq_data, max_freq, min_freq = add_wavemeter_data('', WDATA_FOLDER)
	data = freq_data[:]
	levels = staircase_fit(data)

	data = get_data_frame(MEASURE_FOLDER)
	data.dropna(inplace=True)
	freqs = ((max_freq)-(data['tempV']-data['tempV'].min())*FREQVSVOLT- (data['currV']-data['currV'].min())*FREQVSCURR)
	plt.plot(freqs)
 
	#*-----------------------
	#* GETTING DEPTH_RATIO DATAFRAME
 	#*-----------------------
	MEASURE_FOLDER = r'C:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\CATMeasurements\relScatRate'
	depth_ratios_df = get_rel_scattering_df(MEASURE_FOLDER)
	df_slice = depth_ratios_df[(depth_ratios_df['pa1']==1.85) & (depth_ratios_df['pd1']==84) & (depth_ratios_df['pd2'] == 84)]
	x = df_slice['pa2']
	y = df_slice['depth_ratio']
	plt.plot(x,y, 'o')

	#*-----------------------
	#* MEGA_RUN
 	#*-----------------------	
	MEASURE_FOLDER = os.path.join(EXP_FOLDER, 'testPARunMega')
	df = get_data_frame(MEASURE_FOLDER)
	df.dropna(inplace=True)

	df_grouped = df.groupby(by='pump_reference')
	min_ratios = df_grouped['ratio'].min()

	groups = dict(list(df_grouped))
	dfs = [df for df in groups.values()]
 
	max_freqs = [384182.5]*15
	#max_freqs=[384178.599, 384179.091, 384184.733]
	zipped_data = list(zip(dfs, max_freqs))
	fig, ax = plt.subplots()
	for i, (df, max_freq)  in enumerate(zipped_data[:]):
		data = df.dropna()
		freqs = ((max_freq-PUMP_FREQUENCY)-(data['tempV']-data['tempV'].min())*FREQVSVOLT- (data['currV']-data['currV'].min())*FREQVSCURR)
		ax=plot_spline_fit(ax, x=freqs, y=data['ratio'], yerr=data['ratioErr'],scolor=f'C{i}', mfc=f'C{i}',color=f'C{i}', s=0.0, ms=5, figsize=(10, 10), label=f"Pump Amplituide = { df.iloc[10]['pump_reference'] :.2f}", linewidth=2.5)

	plt.legend()

	plt.savefig(os.path.join(MEASURE_FOLDER, 'lossFeatures.png'))
	#*-----------------------
	#* MULTIPLE MEGARUN
	#*-----------------------
 
	folders = [os.path.join(EXP_FOLDER, path ) for path in ['testPArunMega', 'testPArunMega2']]
	dfs_mega = [get_data_frame(measure_folder, cache_all=True).dropna() for measure_folder in folders]

	dfs_grouped = [df_mega.groupby(by='pump_reference') for df_mega in dfs_mega]
	min_ratios = [df_grouped['ratio'].min() for df_grouped in dfs_grouped]

	groupss = [dict(list(df_grouped)) for df_grouped in dfs_grouped]
	dfs = [ [df for df in groups.values()] for groups in groupss]
 
	for row in dfs:
		x = [df['pump_reference'].mean() for df in row]
		y = [(df['ratio'].max() - df['ratio'].min())/df['motSS'].std() for df in row]
		plt.plot( x, y ,'-o', label=fr"$\delta$ = {180 - 2*row[0]['pump_AOM_freq'].mean()} MHz")
		plt.xlabel('Pump Amplitude')
		plt.ylabel(r'SNR $ = \frac{V_{ss, off} - V_{ss, on}}{\sigma_{V,off}}$ ')
	plt.legend()

def freq_misc():
	WDATA_FOLDER = r'C:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\CATMeasurements\CATcurrTestrun3.csv'
	freq_data = add_wavemeter_data('', WDATA_FOLDER)
	levels = staircase_fit(freq_data[0], peak_height=0.2, distance=50, data_offset=1, window_size=1) 

	plt.close()
 
	x = np.linspace(0, 4.9, 25)
	y = levels
 
	plt.plot(levels, '-o')
	plt.title('Levels plot')
	
	m, b, fit_line = my_linear_fit(x, y)
def save_fit_results(run_path, plot=False):
	filename = os.path.join(run_path, 'data.csv')
	bkfilename = os.path.join(run_path, 'data_oldPD.csv')
	settingsname = os.path.join(run_path, 'Settings.txt')
	
	dataHost = MTdataHost(SAMPLE_RATE)
	dataHost.loadCATdata(fileName=filename, settingsName=settingsname)
	dataHost.CATbackgroundData(bkfilename)
	
	dataHost.setAllCAT(0.002)
	resultDict = dataHost.getResults(run_path, store=True)
 
	if plot:
		dataHost.storeFits(run_path, combined=True, separate=True)
  
	return resultDict, dataHost.settings
		
def get_timestamp(run_path):
	timestamp = datetime.strptime(os.path.split(run_path)[-1].split('_')[0], dateformat)
	return timestamp

def extract_fit(run_path, plot=True, cache_failed=True, cache_all=True):
	"""Gather relevant data from each measurement run

	Args:
		run_path : absolute path to the run directory
		plot (bool, optional): plot fits. Defaults to True.
		cache_failed (bool, optional): Cache failed fits. If false, refit. Doesn't refit non-failed fits. Defaults to True.
		cache_all (bool, optional): If false, ignore any cached fit_results. Defaults to True.

	Returns:
		a 3-tuple (fit_results, settings, timestamp)
	"""
	fit_results, settings, timestamp = {}, {}, None
	
	if not os.path.isdir(run_path):
		return fit_results, settings, timestamp  # directory is not a run directory

	try:
		timestamp = get_timestamp(run_path)
  
  	# TODO: specify which error to catch
	except Exception as e:
		print("Error extracting timestamp from: ", run_path)
		print(traceback.format_exc())
	
	MAT_fit_cache_path = os.path.join(run_path, 'resultDict.txt')
 
	if not os.path.exists(MAT_fit_cache_path) or not cache_all:
		
		try: 
			fit_results, settings = save_fit_results(run_path, plot=plot)
		except Exception as e:
			print(traceback.format_exc())
			print("Fitting ERROR at ", os.path.basename(run_path), '\n')

			with open(MAT_fit_cache_path, 'w') as f:
				f.write(str('MAT fit failed'))
		
	else:
		print("Accessing cached results from :", os.path.basename(run_path))
  
		fit_results = open(MAT_fit_cache_path, 'r').read()

		if fit_results == 'MAT fit failed':
			if not cache_failed:
				# fit regardless of cached result
				try: 
					fit_results, settings = save_fit_results(run_path, plot=plot)
				except Exception as e:
					print(traceback.format_exc())
					print("Fitting ERROR at ", os.path.basename(run_path), '\n')
	
					with open(MAT_fit_cache_path, 'w') as f:
						f.write(str('MAT fit failed'))	
			else:
				print("Failed fit at :", os.path.basename(run_path))
				fit_results = {}

		else:
			fit_results = eval(open(MAT_fit_cache_path, 'r').read())
   
			settingsname = os.path.join(run_path, 'Settings.txt')
			settings = eval(open(settingsname, 'r').read())
   
	return fit_results, settings, timestamp



def get_row(run_path, **kwargs):
			
   fit_results, settings, timestamp = extract_fit(run_path, **kwargs)
   row = {**fit_results, **settings, **{'timestamp':timestamp}}
   
   return row

   
def get_data_frame(data_dir, parallel=True, in_process_run=False, **kwargs):
   
	run_path_arr = []
	rows = []
	
	for relative_path in os.listdir(data_dir):
		run_path_arr.append(os.path.join(data_dir, relative_path))
  
	if in_process_run:
		run_path_arr.pop()

	run_path_arr = sorted(run_path_arr)
	
	if parallel:
		with Pool(4) as p:
			rows = list(tqdm(p.imap(partial(get_row, **kwargs), run_path_arr), total=len(run_path_arr)))
	
	else:
		for run_path in tqdm(run_path_arr):
		   rows.append(get_row(run_path, **kwargs))

	return pd.DataFrame.from_dict(rows)

def add_wavemeter_data(df, wmeter_csv_path, window_size=100, num_rows=50):


	"""Extract unique frequnecy values from wavemeter data
	Returns:
		unique_levels (list): unique frequency values in wavemeter data
	"""
 
	# TODO: modify dataframe in place with frequency data
 
	wdata = pd.read_csv(wmeter_csv_path, skiprows=2)
	wdata.dropna(inplace=True)
	freq_data = np.array(wdata.iloc[:, 0])
	try:
		freq_data = np.array([float(item) for item in freq_data if item.replace('.','').isdigit()])
	except Exception as e:
		print(e)
 
	max_freq = freq_data.max()
	min_freq = freq_data.min()

	return freq_data, max_freq, min_freq

def plot_results(ax, dfs, max_freq, min_freq=0.0, mfc='red', fmt='o', ms=5, save_folder=False, xscale=1.0, yscale=1.0, **kwargs):
	FREQVSVOLT = 221.0 
	FREQVSCURR = 1.13
	
	if not type(dfs) == list:
		freqs = ((max_freq-PUMP_FREQUENCY)-(dfs.dropna()['tempV']-dfs.dropna()['tempV'].min())*FREQVSVOLT- (dfs.dropna()['currV']-dfs.dropna()['currV'].min())*FREQVSCURR)*xscale
		dfs=[dfs]
  
	plt.gcf().set_dpi(300)
	
	for df in dfs:
		df = df.dropna()
		ax.errorbar(freqs, 
			   df['ratio']*yscale,
			   yerr=df['ratioErr'],
			   fmt=fmt, mfc=mfc, color='black', ms=ms, **kwargs)
		ax.set_ylabel(r'$\mathbf{\frac{V_{ss, cat}}{V_{ss}}} $ ', **labeldict)
		ax.set_xlabel(r'$\Delta $ (GHz)', **labeldict)
	
	if save_folder:
		plt.savefig(os.path.join(save_folder, 'ratio_vs_freq.png'))
	
	return freqs, ax
  
	#return plt.gca(), plt.gcf()
	#plt.show()

def plot_spline_fit(ax, x, y, s=1, yerr=None, color='black', scolor='black',figsize=(12,5), save_folder=None, title='',alpha=0.5,dpi=200, label='plot',**kwargs):
	from scipy.interpolate import splev, splrep
	xnew = np.linspace(min(x), max(x), 3*len(x) )

	y = [b for a,b in sorted(zip(x,y), key=lambda pair: pair[0])]
	if yerr is not None:
		yerr = [b for a,b in sorted(zip(x,yerr), key=lambda pair: pair[0])]
 
	x = sorted(x)

	spl = splrep(x, y, s=s)
	ynew = splev(xnew, spl)

	
	plt.gcf().set_dpi(dpi)
	plt.gcf().set_size_inches(figsize)
	
	if yerr is not None:
		ax.errorbar(x, y, yerr=yerr, fmt='o', **kwargs)
	else:
		ax.plot(x,y, 'o', **kwargs)
	ax.plot(xnew, ynew, '-', color=scolor, alpha=alpha, label=label, **kwargs)
 
	ax.set_ylabel(r'$\mathbf{\frac{V_{ss, cat}}{V_{ss}}} $ ', **labeldict)
	ax.set_xlabel(r'$\Delta $ (GHz)', **labeldict)
 
	ax.set_title(title, **titledict)
	if save_folder:
		plt.savefig(os.path.join(save_folder, 'spline_ratio_vs_freq.png'))
	
	return ax
 
def plot_polyfit(x_data, y_data, spline_degree):
	
	coefficients = np.polyfit(x_data, y_data, spline_degree)

	x_interp = np.linspace(min(x_data), max(x_data), 100)
	y_interp = np.polyval(coefficients, x_interp)

	plt.scatter(x_data, y_data, label='Original Data')
	plt.plot(x_interp, y_interp, label='Polynomial Interpolation (Degree={})'.format(spline_degree))

def collect_plots(source, destination, plot_name):
	print(f'Collecting plots from {os.path.basename(source)}')
	import shutil

	os.makedirs(destination, exist_ok=True)

	plot_files = []
	for root, dirs, files in os.walk(source):
		
		for file in files:
			if file == plot_name:
				plot_files.append(os.path.join(root, file))

	for i, plot_file in enumerate(plot_files, start=0):
		new_filename = f'{i}{plot_name}'
		destination_path = os.path.join(destination, new_filename)
		shutil.copy(plot_file, destination_path)

def create_GIF(images_folder, image_name):
	import imageio
	with imageio.get_writer(os.path.join(images_folder, f'{image_name}movie.gif'), mode='I', duration=0.5) as writer:
		for filename in os.listdir(images_folder):
			if image_name in filename:
				image = imageio.imread(os.path.join(images_folder, filename))
				writer.append_data(image)

def staircase_fit(data, peak_height=0.1, distance=100, data_offset=1, window_size=1, inc_final_peak=True):
	def moving_average(arr, window_size):
		weights = np.ones(window_size) / window_size
		return np.convolve(arr, weights, mode='valid')

	convdata1 = moving_average(data, window_size)
	convdata2 = moving_average(data[data_offset+1:], window_size )
	final = convdata1[:len(convdata2)]-convdata2
	# plt.plot(data)
	# plt.plot(convdata1)
	# plt.plot(convdata2)
	# plt.show()
	# plt.plot(final)

	
	from scipy.signal import find_peaks
	x= final
	peaks, _ = find_peaks(x, height=peak_height, distance=distance)
	peaks = np.insert(peaks, 0, 0)
	levels = []
	plot_arr = []
	for i, peak in enumerate(peaks):
		
		if i < len(peaks) - 1:
			temp = data[ peaks[i]:peaks[i+1] ]
			plot_arr.extend( np.ones_like(temp)*np.mean(temp))
			levels.append(np.mean(temp))
	if inc_final_peak:
		temp = data[peaks[-1]:]
		levels.append(np.mean(temp))
		plot_arr.extend( np.ones_like(temp)*np.mean(temp))
  
	plt.plot(x)
	plt.plot(peaks, x[peaks], "x")
	plt.plot(np.zeros_like(x), "--", color="gray")
	plt.show()
	
	plt.plot(data)
	plt.plot(np.ravel((plot_arr)))
	plt.show()
	plt.close()
	plt.plot(np.array(levels)[np.where(abs(np.diff(levels))>0.05)[0]], 'o', ms=5)
 
	return levels

def load_single_run(run_path):
	filename = os.path.join(run_path, 'data.csv')
	bkfilename = os.path.join(run_path, 'data_oldPD.csv')
	settingsname = os.path.join(run_path, 'Settings.txt')
	
	dh1 = MTdataHost(SAMPLE_RATE)
	dh1.loadCATdata(fileName=filename, settingsName=settingsname)
	
	return dh1
	# *-----------------------
	# *RELATIVE SCATTERING RATE
	# *-----------------------


def get_rel_scattering_df(data_folder):
	depth_ratios_df = []
	listdir = sorted(os.listdir(data_folder))
	try:
		for run_folder1, run_folder2 in tqdm([listdir[i:i+2] for i in range(len(listdir))[::2]]):
			try:
				run_path1 = os.path.join(data_folder, run_folder1)
				run_path2 = os.path.join(data_folder, run_folder2)
				result = {}
				with open(os.path.join(run_path1, 'twoSettings.txt'), 'r') as f:
					settings = f.read() 
					import re

					pattern = r'(\w+)\s*=\s*\(([\d.]+),\s*([\d.]+)\)'

					matches = re.findall(pattern, settings)

					
					for match in matches:
						key = match[0]
						value1 = float(match[1])
						value2 = float(match[2])
						result[key] = (value1, value2)

					#print(result)
				with open(os.path.join(run_path2, 'twoSettings.txt'), 'r') as f:
					pass
					#print(f.readlines())
				
				timestamp = get_timestamp(run_path1)
				fit_results1, fit_results2, fit_results, depth_ratio = get_rel_scattering(run_path1, run_path2)
				
				extracted_values = {
						'pa1': result['pd1'][0],
						'pd1': result['pd1'][1],
						'pa2': result['pd2'][0],
						'pd2': result['pd2'][1],
						'depth_ratio': 1/float(depth_ratio), # ratio between current and std settings
	  					'timestamp': timestamp,
						**fit_results
					}
				depth_ratios_df.append(extracted_values)
				
				print('\n')
			except Exception as e:
					print(traceback.format_exc())
					print(f'Error {e} at {run_folder1, run_folder2}')
	except Exception as e:
		print(f'Error {e}')

	depth_ratios_df = pd.DataFrame(depth_ratios_df)
 
	return depth_ratios_df

def get_rel_scattering(run_path1, run_path2):
	resultDict = {}
	
	resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
	resultDict['scat_ratio1'] = scat_ratio1
	resultDict2, scat_ratio2 = _load_single_run_rel_scat(run_path2, plot=True)
	resultDict['scat_ratio2'] = 1/scat_ratio2
	#print(f"scat_ratio 1, (2 inverted) = {scat_ratio1:.3f}, {1/scat_ratio2:.3f}")
	scat_ratio_avg = (scat_ratio1+1/scat_ratio2)/2
	resultDict['scat_ratio_avg'] = scat_ratio_avg
 
	Rratio = resultDict1['initMOTR']/resultDict2['initMOTR']
	resultDict['Rratio'] = Rratio
	#print(fr"Rratio = {resultDict1['initMOTR']:.3f} / {resultDict2['initMOTR']:.3f} = {Rratio:.3f}")
	depthRatio = np.sqrt(Rratio/scat_ratio_avg)
	
	return resultDict1, resultDict2, resultDict, depthRatio


def _load_single_run_rel_scat(run_path, plot=False, cache_all=False):
	filename = os.path.join(run_path, 'data.csv')
	settingsname = os.path.join(run_path, 'Settings.txt')
	
	MAT_fit_cache_path = os.path.join(run_path, 'resultDict.txt')
	fit_results = {}
	if not os.path.exists(MAT_fit_cache_path) or not cache_all:
		
		try: 
			dh1 = MTdataHost(SAMPLE_RATE)
			dh1.loadCATdata(fileName=filename, settingsName=settingsname)

			#dh1.tBaseline = 1
			dh1.tCATbackground = 1
			dh1.tLoad = 2
			dh1.timeLoad = 30
			dh1.tReload = dh1.tLoad + dh1.timeLoad
			dh1.timeReload = 1

			dh1.setOffset()
			#dh1.tCATbackground = dh1.tReload + dh1.timeReload 
			dh1.tBaseline = dh1.tReload + dh1.timeReload
			#dh1.setCATtiming()
			dh1.setAllCAT(0.002)

			print('FITTINGGGGGGGGGGGG')
			fit_results = dh1.getResults(run_path, store=True)
			if plot:
				dh1.storeFits(run_path, combined=True, separate=True)
		except Exception as e:
			print(traceback.format_exc())
			print("Fitting ERROR at ", os.path.basename(run_path), '\n')

			with open(MAT_fit_cache_path, 'w') as f:
				f.write(str('MAT fit failed'))
		
	else:
		print("Accessing cached results from :", os.path.basename(run_path))

		fit_results = open(MAT_fit_cache_path, 'r').read()

		if fit_results == 'MAT fit failed':
			print("Failed fit at :", os.path.basename(run_path))
			fit_results = {}

		else:
			fit_results = eval(open(MAT_fit_cache_path, 'r').read())


	
	#scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
	scat_ratio = (fit_results['motSS']+fit_results['baseVolt']-(fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))/(fit_results['reloadVolt'])
	fit_results['scat_ratio'] = scat_ratio
 	#scat_ratio = dh1.motSS/(dh1.reloadVolt+dh1.baseVolt - (dh1.CATbackgroundVolt+dh1.noLightBackground))
	
	return fit_results, scat_ratio

def scat_rate(I, delta, gamma=6.065, Is=1.669):
	"""_summary_

	Args:
		I (float): intensity (Mhz)
		delta (float): detuning (Mhz)
		gamma (float, optional): linewidth (Mhz) Defaults to 6.065.
		Is (float, optional): Should be one of 3.576(isotropic), 2.503(pi), 1.669 (sigma+-). Defaults to 1.669.

	Returns:
		_type_: gamma: the scattering rate
	"""
	return gamma*I/(2*Is*(1+I/Is+4*(delta/gamma)**2))

if __name__ == '__main__':
	run_path = r"C:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\CATMeasurements\testPArun9\16-53-10"
	filename = os.path.join(run_path, 'data.csv')
	bkfilename = os.path.join(run_path, 'data_oldPD.csv')
	settingsname = os.path.join(run_path, 'Settings.txt')
	
	dh1 = MTdataHost(SAMPLE_RATE)
	dh1.loadCATdata(fileName=filename, settingsName=settingsname)
	
 	#dh1.CATbackgroundData(bkfilename)
	dh1.setAllCAT(0.002)
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
In [ ]:
scat_df = get_rel_scattering_df(r'C:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\CATMeasurements\relScatRate\TrapDepthMap')
  0%|          | 0/121 [00:00<?, ?it/s]
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
  1%|          | 1/121 [00:06<12:48,  6.41s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
  2%|▏         | 2/121 [00:12<12:15,  6.18s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
  2%|▏         | 3/121 [00:18<11:53,  6.05s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
  3%|▎         | 4/121 [00:26<13:16,  6.81s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
  4%|▍         | 5/121 [00:33<13:26,  6.95s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
  5%|▍         | 6/121 [00:39<12:52,  6.72s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
  6%|▌         | 7/121 [00:46<13:04,  6.88s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
  7%|▋         | 8/121 [00:53<12:34,  6.68s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
  7%|▋         | 9/121 [01:01<13:07,  7.03s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
  8%|▊         | 10/121 [01:08<13:16,  7.18s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
  9%|▉         | 11/121 [01:15<12:54,  7.04s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 10%|▉         | 12/121 [01:22<12:58,  7.15s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
<ipython-input-75-5573a15fdb22>:529: RuntimeWarning: invalid value encountered in sqrt
  depthRatio = np.sqrt(Rratio/scat_ratio_avg)
 11%|█         | 13/121 [01:30<13:01,  7.24s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 12%|█▏        | 14/121 [01:37<13:03,  7.32s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 12%|█▏        | 15/121 [01:44<12:35,  7.13s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 13%|█▎        | 16/121 [01:51<12:26,  7.11s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 14%|█▍        | 17/121 [01:57<11:39,  6.72s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 15%|█▍        | 18/121 [02:04<11:39,  6.79s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 16%|█▌        | 19/121 [02:10<11:32,  6.79s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 17%|█▋        | 20/121 [02:17<11:07,  6.61s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 17%|█▋        | 21/121 [02:23<10:45,  6.45s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 18%|█▊        | 22/121 [02:29<10:24,  6.31s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 19%|█▉        | 23/121 [02:34<10:00,  6.13s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 20%|█▉        | 24/121 [02:41<10:02,  6.21s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 21%|██        | 25/121 [02:47<10:02,  6.28s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 21%|██▏       | 26/121 [02:58<12:04,  7.63s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 22%|██▏       | 27/121 [03:06<12:16,  7.83s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 23%|██▎       | 28/121 [03:13<11:23,  7.35s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 24%|██▍       | 29/121 [03:19<10:52,  7.10s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 25%|██▍       | 30/121 [03:27<10:58,  7.23s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 26%|██▌       | 31/121 [03:35<11:33,  7.71s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 26%|██▋       | 32/121 [03:42<11:02,  7.44s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 27%|██▋       | 33/121 [03:50<10:53,  7.42s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 28%|██▊       | 34/121 [03:57<10:46,  7.43s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 29%|██▉       | 35/121 [04:04<10:36,  7.40s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 30%|██▉       | 36/121 [04:10<09:54,  6.99s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 31%|███       | 37/121 [04:24<12:28,  8.91s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 31%|███▏      | 38/121 [04:40<15:15, 11.03s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 32%|███▏      | 39/121 [04:51<15:15, 11.16s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 33%|███▎      | 40/121 [04:58<13:18,  9.86s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 34%|███▍      | 41/121 [05:08<13:15,  9.95s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 35%|███▍      | 42/121 [05:16<12:19,  9.36s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 36%|███▌      | 43/121 [05:29<13:22, 10.29s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 36%|███▋      | 44/121 [05:37<12:28,  9.72s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 37%|███▋      | 45/121 [05:52<14:09, 11.17s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 38%|███▊      | 46/121 [06:06<15:09, 12.12s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 39%|███▉      | 47/121 [06:14<13:32, 10.99s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 40%|███▉      | 48/121 [06:25<13:12, 10.86s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 40%|████      | 49/121 [06:39<14:21, 11.97s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 41%|████▏     | 50/121 [06:50<13:50, 11.69s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 42%|████▏     | 51/121 [06:59<12:37, 10.82s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 43%|████▎     | 52/121 [07:10<12:18, 10.70s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 44%|████▍     | 53/121 [07:26<14:01, 12.38s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 45%|████▍     | 54/121 [07:35<12:43, 11.39s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 45%|████▌     | 55/121 [07:45<12:07, 11.03s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 46%|████▋     | 56/121 [07:54<11:22, 10.49s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 47%|████▋     | 57/121 [08:03<10:35,  9.93s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 48%|████▊     | 58/121 [08:10<09:32,  9.08s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 49%|████▉     | 59/121 [08:17<08:37,  8.35s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 50%|████▉     | 60/121 [08:24<08:08,  8.01s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 50%|█████     | 61/121 [08:30<07:28,  7.47s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 51%|█████     | 62/121 [08:38<07:25,  7.55s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 52%|█████▏    | 63/121 [08:50<08:29,  8.79s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 53%|█████▎    | 64/121 [09:01<08:58,  9.44s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 54%|█████▎    | 65/121 [09:15<10:02, 10.77s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 55%|█████▍    | 66/121 [09:25<09:50, 10.74s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 55%|█████▌    | 67/121 [09:34<09:06, 10.12s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 56%|█████▌    | 68/121 [09:45<09:11, 10.40s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 57%|█████▋    | 69/121 [09:59<09:51, 11.37s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 58%|█████▊    | 70/121 [10:15<11:04, 13.04s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 59%|█████▊    | 71/121 [10:23<09:29, 11.39s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 60%|█████▉    | 72/121 [10:32<08:40, 10.63s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 60%|██████    | 73/121 [10:43<08:31, 10.66s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 61%|██████    | 74/121 [10:53<08:14, 10.52s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 62%|██████▏   | 75/121 [11:01<07:30,  9.80s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 63%|██████▎   | 76/121 [11:09<06:53,  9.19s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 64%|██████▎   | 77/121 [11:18<06:42,  9.16s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 64%|██████▍   | 78/121 [11:33<07:52, 10.99s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 65%|██████▌   | 79/121 [11:47<08:16, 11.82s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 66%|██████▌   | 80/121 [11:53<06:58, 10.20s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 67%|██████▋   | 81/121 [12:02<06:36,  9.90s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 68%|██████▊   | 82/121 [12:18<07:35, 11.67s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 69%|██████▊   | 83/121 [12:30<07:26, 11.76s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 69%|██████▉   | 84/121 [12:42<07:16, 11.79s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 70%|███████   | 85/121 [12:49<06:08, 10.24s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 71%|███████   | 86/121 [13:01<06:18, 10.81s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 72%|███████▏  | 87/121 [13:11<06:02, 10.67s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 73%|███████▎  | 88/121 [13:20<05:33, 10.09s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 74%|███████▎  | 89/121 [13:29<05:14,  9.84s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 74%|███████▍  | 90/121 [13:35<04:30,  8.73s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 75%|███████▌  | 91/121 [13:41<03:56,  7.89s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 76%|███████▌  | 92/121 [13:47<03:33,  7.35s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 77%|███████▋  | 93/121 [13:54<03:23,  7.26s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 78%|███████▊  | 94/121 [14:00<03:02,  6.77s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 79%|███████▊  | 95/121 [14:06<02:53,  6.68s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 79%|███████▉  | 96/121 [14:13<02:42,  6.52s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 80%|████████  | 97/121 [14:21<02:47,  7.00s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 81%|████████  | 98/121 [14:27<02:38,  6.91s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 82%|████████▏ | 99/121 [14:34<02:26,  6.68s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 83%|████████▎ | 100/121 [14:40<02:17,  6.57s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 83%|████████▎ | 101/121 [14:47<02:11,  6.59s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 84%|████████▍ | 102/121 [14:52<01:58,  6.26s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 85%|████████▌ | 103/121 [14:58<01:52,  6.26s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 86%|████████▌ | 104/121 [15:05<01:49,  6.46s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 87%|████████▋ | 105/121 [15:13<01:47,  6.72s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 88%|████████▊ | 106/121 [15:19<01:39,  6.63s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 88%|████████▊ | 107/121 [15:26<01:35,  6.84s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 89%|████████▉ | 108/121 [15:36<01:40,  7.71s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 90%|█████████ | 109/121 [15:42<01:27,  7.26s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 91%|█████████ | 110/121 [15:49<01:17,  7.04s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 92%|█████████▏| 111/121 [15:55<01:07,  6.73s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 93%|█████████▎| 112/121 [16:16<01:39, 11.08s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 93%|█████████▎| 113/121 [16:23<01:18,  9.82s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 94%|█████████▍| 114/121 [16:30<01:03,  9.02s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 95%|█████████▌| 115/121 [16:37<00:51,  8.51s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 96%|█████████▌| 116/121 [16:43<00:38,  7.69s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 97%|█████████▋| 117/121 [16:49<00:28,  7.24s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 98%|█████████▊| 118/121 [16:55<00:20,  6.80s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 98%|█████████▊| 119/121 [17:02<00:13,  6.96s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
 99%|█████████▉| 120/121 [17:10<00:07,  7.05s/it]

File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
FITTINGGGGGGGGGGGG
100%|██████████| 121/121 [17:15<00:00,  8.56s/it]


In [ ]:
scat_df[scat_df['depth_ratio'].isna()]
Out[ ]:
pa1 pd1 pa2 pd2 depth_ratio timestamp scat_ratio1 scat_ratio2 scat_ratio_avg Rratio
12 1.85 84.0 0.690 80.8 NaN 1900-01-01 18:16:49 2.957568 2.682171 2.819870 -18.151483
63 1.85 84.0 0.835 88.0 NaN 1900-01-01 19:47:08 0.924823 1.048797 0.986810 -9.977041
74 1.85 84.0 1.415 88.0 NaN 1900-01-01 20:06:28 1.581415 0.570952 1.076184 -79.685872
In [ ]:
scat_df[scat_df['depth_ratio']<0.3]
Out[ ]:
pa1 pd1 pa2 pd2 depth_ratio timestamp scat_ratio1 scat_ratio2 scat_ratio_avg Rratio
8 1.85 84.0 1.125 88.0 0.145580 1900-01-01 18:09:42 0.950028 0.230033 0.590030 27.840249
19 1.85 84.0 0.690 88.0 0.280564 1900-01-01 18:29:14 0.947641 1.006793 0.977217 12.414471
41 1.85 84.0 0.400 88.0 0.252895 1900-01-01 19:07:58 1.065684 1.104443 1.085063 16.965781
85 1.85 84.0 0.545 88.0 0.243643 1900-01-01 20:22:32 0.963920 1.043803 1.003861 16.910930
107 1.85 84.0 1.560 88.0 0.227863 1900-01-01 20:59:12 4.086833 0.305328 2.196081 42.296172
In [ ]:
plt.plot(scat_df['scat_ratio1'], scat_df['scat_ratio2'])
Out[ ]:
[<matplotlib.lines.Line2D at 0x1b0fa124e50>]
In [ ]:
plt.plot(scat_df['scat_ratio1'], scat_df['scat_ratio2'], '-o')
Out[ ]:
[<matplotlib.lines.Line2D at 0x1b0fa3a4e50>]
In [ ]:
plt.plot(scat_df['scat_ratio1'], scat_df['scat_ratio2'], '-o')
plt.ylim(0,1)
Out[ ]:
(0.0, 1.0)
In [ ]:
plt.plot(scat_df['scat_ratio1'], scat_df['scat_ratio2'], 'o')
plt.ylim(0,1)
Out[ ]:
(0.0, 1.0)
In [ ]:
scat_df.head(10)
Out[ ]:
pa1 pd1 pa2 pd2 depth_ratio timestamp scat_ratio1 scat_ratio2 scat_ratio_avg Rratio
0 1.85 84.0 1.125 82.4 1.060105 1900-01-01 17:56:41 1.651707 1.621480 1.636594 1.456274
1 1.85 84.0 1.125 80.8 0.834277 1900-01-01 17:58:10 2.085987 2.014917 2.050452 2.945972
2 1.85 84.0 1.125 86.4 0.607973 1900-01-01 17:59:38 0.913230 0.914242 0.913736 2.472021
3 1.85 84.0 1.125 85.6 0.728236 1900-01-01 18:01:06 0.981404 0.958251 0.969827 1.828735
4 1.85 84.0 1.125 80.0 0.566797 1900-01-01 18:02:39 2.408469 2.327947 2.368208 7.371643
5 1.85 84.0 1.125 84.0 0.939389 1900-01-01 18:04:24 1.294236 1.238496 1.266366 1.435053
6 1.85 84.0 1.125 81.6 0.777422 1900-01-01 18:06:11 1.871894 1.779275 1.825585 3.020563
7 1.85 84.0 1.125 83.2 1.066557 1900-01-01 18:07:59 1.400588 1.371377 1.385982 1.218399
8 1.85 84.0 1.125 88.0 0.145580 1900-01-01 18:09:42 0.950028 0.230033 0.590030 27.840249
9 1.85 84.0 1.125 87.2 0.503780 1900-01-01 18:11:29 0.880922 0.884991 0.882956 3.479020
In [ ]:
scat_df.tail(10)
Out[ ]:
pa1 pd1 pa2 pd2 depth_ratio timestamp scat_ratio1 scat_ratio2 scat_ratio_avg Rratio
111 1.85 84.0 1.85 80.8 0.701278 1900-01-01 21:05:09 1.532028 0.903196 1.217612 2.475871
112 1.85 84.0 1.85 86.4 0.637039 1900-01-01 21:06:37 0.865055 0.877758 0.871406 2.147282
113 1.85 84.0 1.85 85.6 0.809052 1900-01-01 21:08:04 0.913318 0.862315 0.887817 1.356345
114 1.85 84.0 1.85 80.0 0.370453 1900-01-01 21:09:50 1.760017 0.904101 1.332059 9.706361
115 1.85 84.0 1.85 84.0 0.967908 1900-01-01 21:11:36 1.019432 1.003478 1.011455 1.079639
116 1.85 84.0 1.85 81.6 0.661591 1900-01-01 21:13:13 1.344940 -0.131274 0.606833 1.386405
117 1.85 84.0 1.85 83.2 1.039424 1900-01-01 21:14:41 1.094836 1.065198 1.080017 0.999644
118 1.85 84.0 1.85 88.0 0.793274 1900-01-01 21:16:08 15.370847 -0.021756 7.674545 12.195684
119 1.85 84.0 1.85 87.2 0.539399 1900-01-01 21:17:36 0.916980 0.863904 0.890442 3.060445
120 1.85 84.0 1.85 84.8 0.854043 1900-01-01 21:19:03 0.934381 0.929620 0.932000 1.277782
In [ ]:
scat_df[scat_df['pd2'] = 88.0]
  Cell In[85], line 1
    scat_df[scat_df['pd2'] = 88.0]
            ^
SyntaxError: cannot assign to subscript here. Maybe you meant '==' instead of '='?
In [ ]:
scat_df[scat_df['pd2'] == 88.0]
Out[ ]:
pa1 pd1 pa2 pd2 depth_ratio timestamp scat_ratio1 scat_ratio2 scat_ratio_avg Rratio
8 1.85 84.0 1.125 88.0 0.145580 1900-01-01 18:09:42 0.950028 0.230033 0.590030 27.840249
19 1.85 84.0 0.690 88.0 0.280564 1900-01-01 18:29:14 0.947641 1.006793 0.977217 12.414471
30 1.85 84.0 1.705 88.0 0.548962 1900-01-01 18:48:12 1.031905 -41.445694 -20.206895 -67.052444
41 1.85 84.0 0.400 88.0 0.252895 1900-01-01 19:07:58 1.065684 1.104443 1.085063 16.965781
52 1.85 84.0 0.980 88.0 0.340896 1900-01-01 19:27:24 0.936462 1.068601 1.002531 8.626903
63 1.85 84.0 0.835 88.0 NaN 1900-01-01 19:47:08 0.924823 1.048797 0.986810 -9.977041
74 1.85 84.0 1.415 88.0 NaN 1900-01-01 20:06:28 1.581415 0.570952 1.076184 -79.685872
85 1.85 84.0 0.545 88.0 0.243643 1900-01-01 20:22:32 0.963920 1.043803 1.003861 16.910930
96 1.85 84.0 1.270 88.0 0.877267 1900-01-01 20:40:50 0.914396 0.330400 0.622398 0.808731
107 1.85 84.0 1.560 88.0 0.227863 1900-01-01 20:59:12 4.086833 0.305328 2.196081 42.296172
118 1.85 84.0 1.850 88.0 0.793274 1900-01-01 21:16:08 15.370847 -0.021756 7.674545 12.195684
In [ ]:
scat_df[scat_df['pd2'] < 88.0]
Out[ ]:
pa1 pd1 pa2 pd2 depth_ratio timestamp scat_ratio1 scat_ratio2 scat_ratio_avg Rratio
0 1.85 84.0 1.125 82.4 1.060105 1900-01-01 17:56:41 1.651707 1.621480 1.636594 1.456274
1 1.85 84.0 1.125 80.8 0.834277 1900-01-01 17:58:10 2.085987 2.014917 2.050452 2.945972
2 1.85 84.0 1.125 86.4 0.607973 1900-01-01 17:59:38 0.913230 0.914242 0.913736 2.472021
3 1.85 84.0 1.125 85.6 0.728236 1900-01-01 18:01:06 0.981404 0.958251 0.969827 1.828735
4 1.85 84.0 1.125 80.0 0.566797 1900-01-01 18:02:39 2.408469 2.327947 2.368208 7.371643
... ... ... ... ... ... ... ... ... ... ...
115 1.85 84.0 1.850 84.0 0.967908 1900-01-01 21:11:36 1.019432 1.003478 1.011455 1.079639
116 1.85 84.0 1.850 81.6 0.661591 1900-01-01 21:13:13 1.344940 -0.131274 0.606833 1.386405
117 1.85 84.0 1.850 83.2 1.039424 1900-01-01 21:14:41 1.094836 1.065198 1.080017 0.999644
119 1.85 84.0 1.850 87.2 0.539399 1900-01-01 21:17:36 0.916980 0.863904 0.890442 3.060445
120 1.85 84.0 1.850 84.8 0.854043 1900-01-01 21:19:03 0.934381 0.929620 0.932000 1.277782

110 rows × 10 columns

In [ ]:
scat_df[scat_df['pd2'] == 81.6]
Out[ ]:
pa1 pd1 pa2 pd2 depth_ratio timestamp scat_ratio1 scat_ratio2 scat_ratio_avg Rratio
6 1.85 84.0 1.125 81.6 0.777422 1900-01-01 18:06:11 1.871894 1.779275 1.825585 3.020563
17 1.85 84.0 0.690 81.6 0.467613 1900-01-01 18:25:41 2.601037 2.552349 2.576693 11.783930
28 1.85 84.0 1.705 81.6 1.217380 1900-01-01 18:44:38 1.418993 1.343861 1.381427 0.932129
39 1.85 84.0 0.400 81.6 0.636457 1900-01-01 19:04:25 4.012403 3.708037 3.860220 9.529576
50 1.85 84.0 0.980 81.6 1.049111 1900-01-01 19:23:58 2.136278 1.904376 2.020327 1.835601
61 1.85 84.0 0.835 81.6 1.052341 1900-01-01 19:43:34 2.295847 2.162626 2.229236 2.012995
72 1.85 84.0 1.415 81.6 0.878307 1900-01-01 20:03:16 1.576514 1.502483 1.539499 1.995660
83 1.85 84.0 0.545 81.6 0.815092 1900-01-01 20:19:35 2.968036 2.746715 2.857376 4.300845
94 1.85 84.0 1.270 81.6 1.248490 1900-01-01 20:37:26 1.706670 1.608603 1.657636 1.063454
105 1.85 84.0 1.560 81.6 0.949846 1900-01-01 20:55:47 1.476523 1.427885 1.452204 1.609611
116 1.85 84.0 1.850 81.6 0.661591 1900-01-01 21:13:13 1.344940 -0.131274 0.606833 1.386405
In [ ]:
import os
import sys
from functools import partial
sys.path.append(os.path.join(os.getcwd(), '..')) #adds directory below as valid path
from  datetime import datetime, timedelta
dateformat = "%H-%M-%S"
from collections import deque
import traceback
from multiprocessing import Pool
from tqdm import tqdm

import scipy.constants as spc
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd

plt.rcParams['axes.grid'] = True
plt.rcParams['grid.linestyle'] = '--'

from MT_class_PID_new import MTdataHost
from global_folder.myplotsty import *
from global_folder.my_helpers import *

PUMP_FREQUENCY = 384228.6
REPUMP_FREQUENCY = 384228.6 + 6.56
SAMPLE_RATE = 2000
FREQVSVOLT = 221.0 
FREQVSCURR = 1.13

# TODO: find a better place for this
EXP_FOLDER =r'C:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\CATMeasurements'
MEASURE_FOLDER = os.path.join(EXP_FOLDER, 'testPArun16')
WDATA_FOLDER =os.path.join(MEASURE_FOLDER, 'testPArun16.csv')

# TODO: maybe make a run analysis class out of this?
def dump():
	fig, ax = plt.subplots()
	plot_results(ax, df, max_freq= 384219., fmt='o', mfc='red', save_folder=MEASURE_FOLDER)
	plt.savefig(os.path.join(MEASURE_FOLDER, 'ratio_vs_freq.png'))

	
	collect_plots(MEASURE_FOLDER, os.path.join(MEASURE_FOLDER, 'collected_plots'), 'deloadPhase.png')
 
	#*-----------------------
	#* SINGLE RUN
 	#*----------------------- 
  
	MEASURE_FOLDER = os.path.join(EXP_FOLDER, 'testPArun9')
	df = get_data_frame(MEASURE_FOLDER)
	df.dropna(inplace=True)
	#freqs = plot_results(df, 384201., save_folder=MEASURE_FOLDER)
 
	data = df.dropna()
	freqs = ((384201-PUMP_FREQUENCY)-(data['tempV']-df['tempV'].min())*FREQVSVOLT- (data['currV']-df['currV'].min())*FREQVSCURR)
	fig, ax = plt.subplots()
	plot_spline_fit(ax=ax, x=freqs, y=data['ratio'], yerr=data['ratioErr'], 
				 s=0.1, save_folder=MEASURE_FOLDER, 
				 mfc='red', color='black', 
				 title='Trap Depth = 1.99 K')
 
	# *-----------------------
	# * MULTIPLE RUN COMPARISON
 	# *-----------------------
	folders = [os.path.join(EXP_FOLDER, path ) for path in ['testPARun11', 'testPARun12', 'testPARun13', 'testPARun14']]
	dfs = [get_data_frame(measure_folder, cache_all=True) for measure_folder in folders]

	colors = ['red', 'dodgerblue', 'green', 'grey']
	max_freqs = [384178.881, 384178.593,384179.068, 384184.731]
	#max_freqs=[384178.599, 384179.091, 384184.733]

	zipped_data = list(zip(dfs, max_freqs))
	fig, ax = plt.subplots()
	for i, (df, max_freq)  in enumerate(zipped_data[:3]):
		data = df.dropna()
		freqs = ((max_freq-PUMP_FREQUENCY)-(data['tempV']-data['tempV'].min())*FREQVSVOLT- (data['currV']-data['currV'].min())*FREQVSCURR)
		color = colors[i]
		ax=plot_spline_fit(ax, x=freqs, y=data['ratio'], scolor=color, mfc=color,color=color, s=0.02, ms=5)

	#*-----------------------
	#* PARSING WAVEMETER DATA
 	#*-----------------------

	MEASURE_FOLDER = os.path.join(EXP_FOLDER, 'testPArun14')
	WDATA_FOLDER =os.path.join(MEASURE_FOLDER, 'testPArun14.csv')
	freq_data, max_freq, min_freq = add_wavemeter_data('', WDATA_FOLDER)
	data = freq_data[:]
	levels = staircase_fit(data)

	data = get_data_frame(MEASURE_FOLDER)
	data.dropna(inplace=True)
	freqs = ((max_freq)-(data['tempV']-data['tempV'].min())*FREQVSVOLT- (data['currV']-data['currV'].min())*FREQVSCURR)
	plt.plot(freqs)
 
	#*-----------------------
	#* GETTING DEPTH_RATIO DATAFRAME
 	#*-----------------------
	MEASURE_FOLDER = r'C:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\CATMeasurements\relScatRate'
	depth_ratios_df = get_rel_scattering_df(MEASURE_FOLDER)
	df_slice = depth_ratios_df[(depth_ratios_df['pa1']==1.85) & (depth_ratios_df['pd1']==84) & (depth_ratios_df['pd2'] == 84)]
	x = df_slice['pa2']
	y = df_slice['depth_ratio']
	plt.plot(x,y, 'o')

	#*-----------------------
	#* MEGA_RUN
 	#*-----------------------	
	MEASURE_FOLDER = os.path.join(EXP_FOLDER, 'testPARunMega')
	df = get_data_frame(MEASURE_FOLDER)
	df.dropna(inplace=True)

	df_grouped = df.groupby(by='pump_reference')
	min_ratios = df_grouped['ratio'].min()

	groups = dict(list(df_grouped))
	dfs = [df for df in groups.values()]
 
	max_freqs = [384182.5]*15
	#max_freqs=[384178.599, 384179.091, 384184.733]
	zipped_data = list(zip(dfs, max_freqs))
	fig, ax = plt.subplots()
	for i, (df, max_freq)  in enumerate(zipped_data[:]):
		data = df.dropna()
		freqs = ((max_freq-PUMP_FREQUENCY)-(data['tempV']-data['tempV'].min())*FREQVSVOLT- (data['currV']-data['currV'].min())*FREQVSCURR)
		ax=plot_spline_fit(ax, x=freqs, y=data['ratio'], yerr=data['ratioErr'],scolor=f'C{i}', mfc=f'C{i}',color=f'C{i}', s=0.0, ms=5, figsize=(10, 10), label=f"Pump Amplituide = { df.iloc[10]['pump_reference'] :.2f}", linewidth=2.5)

	plt.legend()

	plt.savefig(os.path.join(MEASURE_FOLDER, 'lossFeatures.png'))
	#*-----------------------
	#* MULTIPLE MEGARUN
	#*-----------------------
 
	folders = [os.path.join(EXP_FOLDER, path ) for path in ['testPArunMega', 'testPArunMega2']]
	dfs_mega = [get_data_frame(measure_folder, cache_all=True).dropna() for measure_folder in folders]

	dfs_grouped = [df_mega.groupby(by='pump_reference') for df_mega in dfs_mega]
	min_ratios = [df_grouped['ratio'].min() for df_grouped in dfs_grouped]

	groupss = [dict(list(df_grouped)) for df_grouped in dfs_grouped]
	dfs = [ [df for df in groups.values()] for groups in groupss]
 
	for row in dfs:
		x = [df['pump_reference'].mean() for df in row]
		y = [(df['ratio'].max() - df['ratio'].min())/df['motSS'].std() for df in row]
		plt.plot( x, y ,'-o', label=fr"$\delta$ = {180 - 2*row[0]['pump_AOM_freq'].mean()} MHz")
		plt.xlabel('Pump Amplitude')
		plt.ylabel(r'SNR $ = \frac{V_{ss, off} - V_{ss, on}}{\sigma_{V,off}}$ ')
	plt.legend()

def freq_misc():
	WDATA_FOLDER = r'C:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\CATMeasurements\CATcurrTestrun3.csv'
	freq_data = add_wavemeter_data('', WDATA_FOLDER)
	levels = staircase_fit(freq_data[0], peak_height=0.2, distance=50, data_offset=1, window_size=1) 

	plt.close()
 
	x = np.linspace(0, 4.9, 25)
	y = levels
 
	plt.plot(levels, '-o')
	plt.title('Levels plot')
	
	m, b, fit_line = my_linear_fit(x, y)
def save_fit_results(run_path, plot=False):
	filename = os.path.join(run_path, 'data.csv')
	bkfilename = os.path.join(run_path, 'data_oldPD.csv')
	settingsname = os.path.join(run_path, 'Settings.txt')
	
	dataHost = MTdataHost(SAMPLE_RATE)
	dataHost.loadCATdata(fileName=filename, settingsName=settingsname)
	dataHost.CATbackgroundData(bkfilename)
	
	dataHost.setAllCAT(0.002)
	resultDict = dataHost.getResults(run_path, store=True)
 
	if plot:
		dataHost.storeFits(run_path, combined=True, separate=True)
  
	return resultDict, dataHost.settings
		
def get_timestamp(run_path):
	timestamp = datetime.strptime(os.path.split(run_path)[-1].split('_')[0], dateformat)
	return timestamp

def extract_fit(run_path, plot=True, cache_failed=True, cache_all=True):
	"""Gather relevant data from each measurement run

	Args:
		run_path : absolute path to the run directory
		plot (bool, optional): plot fits. Defaults to True.
		cache_failed (bool, optional): Cache failed fits. If false, refit. Doesn't refit non-failed fits. Defaults to True.
		cache_all (bool, optional): If false, ignore any cached fit_results. Defaults to True.

	Returns:
		a 3-tuple (fit_results, settings, timestamp)
	"""
	fit_results, settings, timestamp = {}, {}, None
	
	if not os.path.isdir(run_path):
		return fit_results, settings, timestamp  # directory is not a run directory

	try:
		timestamp = get_timestamp(run_path)
  
  	# TODO: specify which error to catch
	except Exception as e:
		print("Error extracting timestamp from: ", run_path)
		print(traceback.format_exc())
	
	MAT_fit_cache_path = os.path.join(run_path, 'resultDict.txt')
 
	if not os.path.exists(MAT_fit_cache_path) or not cache_all:
		
		try: 
			fit_results, settings = save_fit_results(run_path, plot=plot)
		except Exception as e:
			print(traceback.format_exc())
			print("Fitting ERROR at ", os.path.basename(run_path), '\n')

			with open(MAT_fit_cache_path, 'w') as f:
				f.write(str('MAT fit failed'))
		
	else:
		print("Accessing cached results from :", os.path.basename(run_path))
  
		fit_results = open(MAT_fit_cache_path, 'r').read()

		if fit_results == 'MAT fit failed':
			if not cache_failed:
				# fit regardless of cached result
				try: 
					fit_results, settings = save_fit_results(run_path, plot=plot)
				except Exception as e:
					print(traceback.format_exc())
					print("Fitting ERROR at ", os.path.basename(run_path), '\n')
	
					with open(MAT_fit_cache_path, 'w') as f:
						f.write(str('MAT fit failed'))	
			else:
				print("Failed fit at :", os.path.basename(run_path))
				fit_results = {}

		else:
			fit_results = eval(open(MAT_fit_cache_path, 'r').read())
   
			settingsname = os.path.join(run_path, 'Settings.txt')
			settings = eval(open(settingsname, 'r').read())
   
	return fit_results, settings, timestamp



def get_row(run_path, **kwargs):
			
   fit_results, settings, timestamp = extract_fit(run_path, **kwargs)
   row = {**fit_results, **settings, **{'timestamp':timestamp}}
   
   return row

   
def get_data_frame(data_dir, parallel=True, in_process_run=False, **kwargs):
   
	run_path_arr = []
	rows = []
	
	for relative_path in os.listdir(data_dir):
		run_path_arr.append(os.path.join(data_dir, relative_path))
  
	if in_process_run:
		run_path_arr.pop()

	run_path_arr = sorted(run_path_arr)
	
	if parallel:
		with Pool(4) as p:
			rows = list(tqdm(p.imap(partial(get_row, **kwargs), run_path_arr), total=len(run_path_arr)))
	
	else:
		for run_path in tqdm(run_path_arr):
		   rows.append(get_row(run_path, **kwargs))

	return pd.DataFrame.from_dict(rows)

def add_wavemeter_data(df, wmeter_csv_path, window_size=100, num_rows=50):


	"""Extract unique frequnecy values from wavemeter data
	Returns:
		unique_levels (list): unique frequency values in wavemeter data
	"""
 
	# TODO: modify dataframe in place with frequency data
 
	wdata = pd.read_csv(wmeter_csv_path, skiprows=2)
	wdata.dropna(inplace=True)
	freq_data = np.array(wdata.iloc[:, 0])
	try:
		freq_data = np.array([float(item) for item in freq_data if item.replace('.','').isdigit()])
	except Exception as e:
		print(e)
 
	max_freq = freq_data.max()
	min_freq = freq_data.min()

	return freq_data, max_freq, min_freq

def plot_results(ax, dfs, max_freq, min_freq=0.0, mfc='red', fmt='o', ms=5, save_folder=False, xscale=1.0, yscale=1.0, **kwargs):
	FREQVSVOLT = 221.0 
	FREQVSCURR = 1.13
	
	if not type(dfs) == list:
		freqs = ((max_freq-PUMP_FREQUENCY)-(dfs.dropna()['tempV']-dfs.dropna()['tempV'].min())*FREQVSVOLT- (dfs.dropna()['currV']-dfs.dropna()['currV'].min())*FREQVSCURR)*xscale
		dfs=[dfs]
  
	plt.gcf().set_dpi(300)
	
	for df in dfs:
		df = df.dropna()
		ax.errorbar(freqs, 
			   df['ratio']*yscale,
			   yerr=df['ratioErr'],
			   fmt=fmt, mfc=mfc, color='black', ms=ms, **kwargs)
		ax.set_ylabel(r'$\mathbf{\frac{V_{ss, cat}}{V_{ss}}} $ ', **labeldict)
		ax.set_xlabel(r'$\Delta $ (GHz)', **labeldict)
	
	if save_folder:
		plt.savefig(os.path.join(save_folder, 'ratio_vs_freq.png'))
	
	return freqs, ax
  
	#return plt.gca(), plt.gcf()
	#plt.show()

def plot_spline_fit(ax, x, y, s=1, yerr=None, color='black', scolor='black',figsize=(12,5), save_folder=None, title='',alpha=0.5,dpi=200, label='plot',**kwargs):
	from scipy.interpolate import splev, splrep
	xnew = np.linspace(min(x), max(x), 3*len(x) )

	y = [b for a,b in sorted(zip(x,y), key=lambda pair: pair[0])]
	if yerr is not None:
		yerr = [b for a,b in sorted(zip(x,yerr), key=lambda pair: pair[0])]
 
	x = sorted(x)

	spl = splrep(x, y, s=s)
	ynew = splev(xnew, spl)

	
	plt.gcf().set_dpi(dpi)
	plt.gcf().set_size_inches(figsize)
	
	if yerr is not None:
		ax.errorbar(x, y, yerr=yerr, fmt='o', **kwargs)
	else:
		ax.plot(x,y, 'o', **kwargs)
	ax.plot(xnew, ynew, '-', color=scolor, alpha=alpha, label=label, **kwargs)
 
	ax.set_ylabel(r'$\mathbf{\frac{V_{ss, cat}}{V_{ss}}} $ ', **labeldict)
	ax.set_xlabel(r'$\Delta $ (GHz)', **labeldict)
 
	ax.set_title(title, **titledict)
	if save_folder:
		plt.savefig(os.path.join(save_folder, 'spline_ratio_vs_freq.png'))
	
	return ax
 
def plot_polyfit(x_data, y_data, spline_degree):
	
	coefficients = np.polyfit(x_data, y_data, spline_degree)

	x_interp = np.linspace(min(x_data), max(x_data), 100)
	y_interp = np.polyval(coefficients, x_interp)

	plt.scatter(x_data, y_data, label='Original Data')
	plt.plot(x_interp, y_interp, label='Polynomial Interpolation (Degree={})'.format(spline_degree))

def collect_plots(source, destination, plot_name):
	print(f'Collecting plots from {os.path.basename(source)}')
	import shutil

	os.makedirs(destination, exist_ok=True)

	plot_files = []
	for root, dirs, files in os.walk(source):
		
		for file in files:
			if file == plot_name:
				plot_files.append(os.path.join(root, file))

	for i, plot_file in enumerate(plot_files, start=0):
		new_filename = f'{i}{plot_name}'
		destination_path = os.path.join(destination, new_filename)
		shutil.copy(plot_file, destination_path)

def create_GIF(images_folder, image_name):
	import imageio
	with imageio.get_writer(os.path.join(images_folder, f'{image_name}movie.gif'), mode='I', duration=0.5) as writer:
		for filename in os.listdir(images_folder):
			if image_name in filename:
				image = imageio.imread(os.path.join(images_folder, filename))
				writer.append_data(image)

def staircase_fit(data, peak_height=0.1, distance=100, data_offset=1, window_size=1, inc_final_peak=True):
	def moving_average(arr, window_size):
		weights = np.ones(window_size) / window_size
		return np.convolve(arr, weights, mode='valid')

	convdata1 = moving_average(data, window_size)
	convdata2 = moving_average(data[data_offset+1:], window_size )
	final = convdata1[:len(convdata2)]-convdata2
	# plt.plot(data)
	# plt.plot(convdata1)
	# plt.plot(convdata2)
	# plt.show()
	# plt.plot(final)

	
	from scipy.signal import find_peaks
	x= final
	peaks, _ = find_peaks(x, height=peak_height, distance=distance)
	peaks = np.insert(peaks, 0, 0)
	levels = []
	plot_arr = []
	for i, peak in enumerate(peaks):
		
		if i < len(peaks) - 1:
			temp = data[ peaks[i]:peaks[i+1] ]
			plot_arr.extend( np.ones_like(temp)*np.mean(temp))
			levels.append(np.mean(temp))
	if inc_final_peak:
		temp = data[peaks[-1]:]
		levels.append(np.mean(temp))
		plot_arr.extend( np.ones_like(temp)*np.mean(temp))
  
	plt.plot(x)
	plt.plot(peaks, x[peaks], "x")
	plt.plot(np.zeros_like(x), "--", color="gray")
	plt.show()
	
	plt.plot(data)
	plt.plot(np.ravel((plot_arr)))
	plt.show()
	plt.close()
	plt.plot(np.array(levels)[np.where(abs(np.diff(levels))>0.05)[0]], 'o', ms=5)
 
	return levels

def load_single_run(run_path):
	filename = os.path.join(run_path, 'data.csv')
	bkfilename = os.path.join(run_path, 'data_oldPD.csv')
	settingsname = os.path.join(run_path, 'Settings.txt')
	
	dh1 = MTdataHost(SAMPLE_RATE)
	dh1.loadCATdata(fileName=filename, settingsName=settingsname)
	
	return dh1
	# *-----------------------
	# *RELATIVE SCATTERING RATE
	# *-----------------------

def get_rel_scattering_row(run_path_couple):
	run_path1, run_path2 = run_path_couple
	# run_path1 = os.path.join(data_folder, run_folder1)
	# run_path2 = os.path.join(data_folder, run_folder2)
	result = {}
	with open(os.path.join(run_path1, 'twoSettings.txt'), 'r') as f:
		settings = f.read() 
		import re

		pattern = r'(\w+)\s*=\s*\(([\d.]+),\s*([\d.]+)\)'

		matches = re.findall(pattern, settings)

		
		for match in matches:
			key = match[0]
			value1 = float(match[1])
			value2 = float(match[2])
			result[key] = (value1, value2)

		#print(result)
	with open(os.path.join(run_path2, 'twoSettings.txt'), 'r') as f:
		pass
	
	timestamp = get_timestamp(run_path1)
	fit_results1, fit_results2, fit_results, depth_ratio = get_rel_scattering(run_path1, run_path2)
	
	extracted_values = {
			'pa1': result['pd1'][0],
			'pd1': result['pd1'][1],
			'pa2': result['pd2'][0],
			'pd2': result['pd2'][1],
			'depth_ratio': 1/float(depth_ratio), # ratio between current and std settings
			'timestamp': timestamp,
			**fit_results
		}
	return extracted_values
 
def get_rel_scattering_df(data_folder, parallel=False, **kwargs):
	
	listdir = sorted(os.listdir(data_folder))
	run_path_couple_arr = [[os.path.join(data_folder,run_folder1),os.path.join(data_folder,run_folder2)] in [listdir[i:i+2] for i in range(len(listdir))[::2]]]
	 
 
	if parallel:
		with Pool(4) as p:
			rows = list(tqdm(p.imap(partial(get_rel_scattering_row, **kwargs), run_path_couple_arr), total=len(run_path_couple_arr)))
	
	try:
		for run_folder1, run_folder2 in tqdm([listdir[i:i+2] for i in range(len(listdir))[::2]]):
			try:
				run_path1 = os.path.join(data_folder, run_folder1)
				run_path2 = os.path.join(data_folder, run_folder2)
				result = {}
				with open(os.path.join(run_path1, 'twoSettings.txt'), 'r') as f:
					settings = f.read() 
					import re

					pattern = r'(\w+)\s*=\s*\(([\d.]+),\s*([\d.]+)\)'

					matches = re.findall(pattern, settings)

					
					for match in matches:
						key = match[0]
						value1 = float(match[1])
						value2 = float(match[2])
						result[key] = (value1, value2)

					#print(result)
				with open(os.path.join(run_path2, 'twoSettings.txt'), 'r') as f:
					pass
					#print(f.readlines())
				
				timestamp = get_timestamp(run_path1)
				fit_results1, fit_results2, fit_results, depth_ratio = get_rel_scattering(run_path1, run_path2)
				
				extracted_values = {
						'pa1': result['pd1'][0],
						'pd1': result['pd1'][1],
						'pa2': result['pd2'][0],
						'pd2': result['pd2'][1],
						'depth_ratio': 1/float(depth_ratio), # ratio between current and std settings
	  					'timestamp': timestamp,
						**fit_results
					}
				depth_ratios_df.append(extracted_values)
				
				print('\n')
			except Exception as e:
					print(traceback.format_exc())
					print(f'Error {e} at {run_folder1, run_folder2}')
	except Exception as e:
		print(f'Error {e}')

	depth_ratios_df = pd.DataFrame(depth_ratios_df)
 
	return depth_ratios_df

def get_rel_scattering(run_path1, run_path2):
	resultDict = {}
	
	resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
	resultDict['scat_ratio1'] = scat_ratio1
	resultDict2, scat_ratio2 = _load_single_run_rel_scat(run_path2, plot=True)
	resultDict['scat_ratio2'] = 1/scat_ratio2
	#print(f"scat_ratio 1, (2 inverted) = {scat_ratio1:.3f}, {1/scat_ratio2:.3f}")
	#scat_ratio_avg = (scat_ratio1+1/scat_ratio2)/2
 	scat_ratio_avg = scat_ratio1
	resultDict['scat_ratio_avg'] = scat_ratio_avg
 
	Rratio = resultDict1['initMOTR']/resultDict2['initMOTR']
	resultDict['Rratio'] = Rratio
	#print(fr"Rratio = {resultDict1['initMOTR']:.3f} / {resultDict2['initMOTR']:.3f} = {Rratio:.3f}")
	depthRatio = np.sqrt(Rratio/scat_ratio_avg)
	
	return resultDict1, resultDict2, resultDict, depthRatio


def _load_single_run_rel_scat(run_path, plot=False, cache_all=False):
	filename = os.path.join(run_path, 'data.csv')
	settingsname = os.path.join(run_path, 'Settings.txt')
	
	MAT_fit_cache_path = os.path.join(run_path, 'resultDict.txt')
	fit_results = {}
	if not os.path.exists(MAT_fit_cache_path) or not cache_all:
		
		try: 
			dh1 = MTdataHost(SAMPLE_RATE)
			dh1.loadCATdata(fileName=filename, settingsName=settingsname)

			#dh1.tBaseline = 1
			dh1.tCATbackground = 1
			dh1.tLoad = 2
			dh1.timeLoad = 30
			dh1.tReload = dh1.tLoad + dh1.timeLoad
			dh1.timeReload = 1

			dh1.setOffset()
			#dh1.tCATbackground = dh1.tReload + dh1.timeReload 
			dh1.tBaseline = dh1.tReload + dh1.timeReload
			#dh1.setCATtiming()
			dh1.setAllCAT(0.002)

			print('FITTINGGGGGGGGGGGG')
			fit_results = dh1.getResults(run_path, store=True)
			if plot:
				dh1.storeFits(run_path, combined=True, separate=True)
		except Exception as e:
			print(traceback.format_exc())
			print("Fitting ERROR at ", os.path.basename(run_path), '\n')

			with open(MAT_fit_cache_path, 'w') as f:
				f.write(str('MAT fit failed'))
		
	else:
		print("Accessing cached results from :", os.path.basename(run_path))

		fit_results = open(MAT_fit_cache_path, 'r').read()

		if fit_results == 'MAT fit failed':
			print("Failed fit at :", os.path.basename(run_path))
			fit_results = {}

		else:
			fit_results = eval(open(MAT_fit_cache_path, 'r').read())


	
	#scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
	scat_ratio = (fit_results['motSS']+fit_results['baseVolt']-(fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))/(fit_results['reloadVolt'])
	fit_results['scat_ratio'] = scat_ratio
 	#scat_ratio = dh1.motSS/(dh1.reloadVolt+dh1.baseVolt - (dh1.CATbackgroundVolt+dh1.noLightBackground))
	
	return fit_results, scat_ratio

def scat_rate(I, delta, gamma=6.065, Is=1.669):
	"""_summary_

	Args:
		I (float): intensity (Mhz)
		delta (float): detuning (Mhz)
		gamma (float, optional): linewidth (Mhz) Defaults to 6.065.
		Is (float, optional): Should be one of 3.576(isotropic), 2.503(pi), 1.669 (sigma+-). Defaults to 1.669.

	Returns:
		_type_: gamma: the scattering rate
	"""
	return gamma*I/(2*Is*(1+I/Is+4*(delta/gamma)**2))

if __name__ == '__main__':
	run_path = r"C:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\CATMeasurements\testPArun9\16-53-10"
	filename = os.path.join(run_path, 'data.csv')
	bkfilename = os.path.join(run_path, 'data_oldPD.csv')
	settingsname = os.path.join(run_path, 'Settings.txt')
	
	dh1 = MTdataHost(SAMPLE_RATE)
	dh1.loadCATdata(fileName=filename, settingsName=settingsname)
	
 	#dh1.CATbackgroundData(bkfilename)
	dh1.setAllCAT(0.002)
  Cell In[89], line 568
    scat_ratio_avg = scat_ratio1
    ^
TabError: inconsistent use of tabs and spaces in indentation
In [ ]:
import os
import sys
from functools import partial
sys.path.append(os.path.join(os.getcwd(), '..')) #adds directory below as valid path
from  datetime import datetime, timedelta
dateformat = "%H-%M-%S"
from collections import deque
import traceback
from multiprocessing import Pool
from tqdm import tqdm

import scipy.constants as spc
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd

plt.rcParams['axes.grid'] = True
plt.rcParams['grid.linestyle'] = '--'

from MT_class_PID_new import MTdataHost
from global_folder.myplotsty import *
from global_folder.my_helpers import *

PUMP_FREQUENCY = 384228.6
REPUMP_FREQUENCY = 384228.6 + 6.56
SAMPLE_RATE = 2000
FREQVSVOLT = 221.0 
FREQVSCURR = 1.13

# TODO: find a better place for this
EXP_FOLDER =r'C:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\CATMeasurements'
MEASURE_FOLDER = os.path.join(EXP_FOLDER, 'testPArun16')
WDATA_FOLDER =os.path.join(MEASURE_FOLDER, 'testPArun16.csv')

# TODO: maybe make a run analysis class out of this?
def dump():
	fig, ax = plt.subplots()
	plot_results(ax, df, max_freq= 384219., fmt='o', mfc='red', save_folder=MEASURE_FOLDER)
	plt.savefig(os.path.join(MEASURE_FOLDER, 'ratio_vs_freq.png'))

	
	collect_plots(MEASURE_FOLDER, os.path.join(MEASURE_FOLDER, 'collected_plots'), 'deloadPhase.png')
 
	#*-----------------------
	#* SINGLE RUN
 	#*----------------------- 
  
	MEASURE_FOLDER = os.path.join(EXP_FOLDER, 'testPArun9')
	df = get_data_frame(MEASURE_FOLDER)
	df.dropna(inplace=True)
	#freqs = plot_results(df, 384201., save_folder=MEASURE_FOLDER)
 
	data = df.dropna()
	freqs = ((384201-PUMP_FREQUENCY)-(data['tempV']-df['tempV'].min())*FREQVSVOLT- (data['currV']-df['currV'].min())*FREQVSCURR)
	fig, ax = plt.subplots()
	plot_spline_fit(ax=ax, x=freqs, y=data['ratio'], yerr=data['ratioErr'], 
				 s=0.1, save_folder=MEASURE_FOLDER, 
				 mfc='red', color='black', 
				 title='Trap Depth = 1.99 K')
 
	# *-----------------------
	# * MULTIPLE RUN COMPARISON
 	# *-----------------------
	folders = [os.path.join(EXP_FOLDER, path ) for path in ['testPARun11', 'testPARun12', 'testPARun13', 'testPARun14']]
	dfs = [get_data_frame(measure_folder, cache_all=True) for measure_folder in folders]

	colors = ['red', 'dodgerblue', 'green', 'grey']
	max_freqs = [384178.881, 384178.593,384179.068, 384184.731]
	#max_freqs=[384178.599, 384179.091, 384184.733]

	zipped_data = list(zip(dfs, max_freqs))
	fig, ax = plt.subplots()
	for i, (df, max_freq)  in enumerate(zipped_data[:3]):
		data = df.dropna()
		freqs = ((max_freq-PUMP_FREQUENCY)-(data['tempV']-data['tempV'].min())*FREQVSVOLT- (data['currV']-data['currV'].min())*FREQVSCURR)
		color = colors[i]
		ax=plot_spline_fit(ax, x=freqs, y=data['ratio'], scolor=color, mfc=color,color=color, s=0.02, ms=5)

	#*-----------------------
	#* PARSING WAVEMETER DATA
 	#*-----------------------

	MEASURE_FOLDER = os.path.join(EXP_FOLDER, 'testPArun14')
	WDATA_FOLDER =os.path.join(MEASURE_FOLDER, 'testPArun14.csv')
	freq_data, max_freq, min_freq = add_wavemeter_data('', WDATA_FOLDER)
	data = freq_data[:]
	levels = staircase_fit(data)

	data = get_data_frame(MEASURE_FOLDER)
	data.dropna(inplace=True)
	freqs = ((max_freq)-(data['tempV']-data['tempV'].min())*FREQVSVOLT- (data['currV']-data['currV'].min())*FREQVSCURR)
	plt.plot(freqs)
 
	#*-----------------------
	#* GETTING DEPTH_RATIO DATAFRAME
 	#*-----------------------
	MEASURE_FOLDER = r'C:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\CATMeasurements\relScatRate'
	depth_ratios_df = get_rel_scattering_df(MEASURE_FOLDER)
	df_slice = depth_ratios_df[(depth_ratios_df['pa1']==1.85) & (depth_ratios_df['pd1']==84) & (depth_ratios_df['pd2'] == 84)]
	x = df_slice['pa2']
	y = df_slice['depth_ratio']
	plt.plot(x,y, 'o')

	#*-----------------------
	#* MEGA_RUN
 	#*-----------------------	
	MEASURE_FOLDER = os.path.join(EXP_FOLDER, 'testPARunMega')
	df = get_data_frame(MEASURE_FOLDER)
	df.dropna(inplace=True)

	df_grouped = df.groupby(by='pump_reference')
	min_ratios = df_grouped['ratio'].min()

	groups = dict(list(df_grouped))
	dfs = [df for df in groups.values()]
 
	max_freqs = [384182.5]*15
	#max_freqs=[384178.599, 384179.091, 384184.733]
	zipped_data = list(zip(dfs, max_freqs))
	fig, ax = plt.subplots()
	for i, (df, max_freq)  in enumerate(zipped_data[:]):
		data = df.dropna()
		freqs = ((max_freq-PUMP_FREQUENCY)-(data['tempV']-data['tempV'].min())*FREQVSVOLT- (data['currV']-data['currV'].min())*FREQVSCURR)
		ax=plot_spline_fit(ax, x=freqs, y=data['ratio'], yerr=data['ratioErr'],scolor=f'C{i}', mfc=f'C{i}',color=f'C{i}', s=0.0, ms=5, figsize=(10, 10), label=f"Pump Amplituide = { df.iloc[10]['pump_reference'] :.2f}", linewidth=2.5)

	plt.legend()

	plt.savefig(os.path.join(MEASURE_FOLDER, 'lossFeatures.png'))
	#*-----------------------
	#* MULTIPLE MEGARUN
	#*-----------------------
 
	folders = [os.path.join(EXP_FOLDER, path ) for path in ['testPArunMega', 'testPArunMega2']]
	dfs_mega = [get_data_frame(measure_folder, cache_all=True).dropna() for measure_folder in folders]

	dfs_grouped = [df_mega.groupby(by='pump_reference') for df_mega in dfs_mega]
	min_ratios = [df_grouped['ratio'].min() for df_grouped in dfs_grouped]

	groupss = [dict(list(df_grouped)) for df_grouped in dfs_grouped]
	dfs = [ [df for df in groups.values()] for groups in groupss]
 
	for row in dfs:
		x = [df['pump_reference'].mean() for df in row]
		y = [(df['ratio'].max() - df['ratio'].min())/df['motSS'].std() for df in row]
		plt.plot( x, y ,'-o', label=fr"$\delta$ = {180 - 2*row[0]['pump_AOM_freq'].mean()} MHz")
		plt.xlabel('Pump Amplitude')
		plt.ylabel(r'SNR $ = \frac{V_{ss, off} - V_{ss, on}}{\sigma_{V,off}}$ ')
	plt.legend()

def freq_misc():
	WDATA_FOLDER = r'C:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\CATMeasurements\CATcurrTestrun3.csv'
	freq_data = add_wavemeter_data('', WDATA_FOLDER)
	levels = staircase_fit(freq_data[0], peak_height=0.2, distance=50, data_offset=1, window_size=1) 

	plt.close()
 
	x = np.linspace(0, 4.9, 25)
	y = levels
 
	plt.plot(levels, '-o')
	plt.title('Levels plot')
	
	m, b, fit_line = my_linear_fit(x, y)
def save_fit_results(run_path, plot=False):
	filename = os.path.join(run_path, 'data.csv')
	bkfilename = os.path.join(run_path, 'data_oldPD.csv')
	settingsname = os.path.join(run_path, 'Settings.txt')
	
	dataHost = MTdataHost(SAMPLE_RATE)
	dataHost.loadCATdata(fileName=filename, settingsName=settingsname)
	dataHost.CATbackgroundData(bkfilename)
	
	dataHost.setAllCAT(0.002)
	resultDict = dataHost.getResults(run_path, store=True)
 
	if plot:
		dataHost.storeFits(run_path, combined=True, separate=True)
  
	return resultDict, dataHost.settings
		
def get_timestamp(run_path):
	timestamp = datetime.strptime(os.path.split(run_path)[-1].split('_')[0], dateformat)
	return timestamp

def extract_fit(run_path, plot=True, cache_failed=True, cache_all=True):
	"""Gather relevant data from each measurement run

	Args:
		run_path : absolute path to the run directory
		plot (bool, optional): plot fits. Defaults to True.
		cache_failed (bool, optional): Cache failed fits. If false, refit. Doesn't refit non-failed fits. Defaults to True.
		cache_all (bool, optional): If false, ignore any cached fit_results. Defaults to True.

	Returns:
		a 3-tuple (fit_results, settings, timestamp)
	"""
	fit_results, settings, timestamp = {}, {}, None
	
	if not os.path.isdir(run_path):
		return fit_results, settings, timestamp  # directory is not a run directory

	try:
		timestamp = get_timestamp(run_path)
  
  	# TODO: specify which error to catch
	except Exception as e:
		print("Error extracting timestamp from: ", run_path)
		print(traceback.format_exc())
	
	MAT_fit_cache_path = os.path.join(run_path, 'resultDict.txt')
 
	if not os.path.exists(MAT_fit_cache_path) or not cache_all:
		
		try: 
			fit_results, settings = save_fit_results(run_path, plot=plot)
		except Exception as e:
			print(traceback.format_exc())
			print("Fitting ERROR at ", os.path.basename(run_path), '\n')

			with open(MAT_fit_cache_path, 'w') as f:
				f.write(str('MAT fit failed'))
		
	else:
		print("Accessing cached results from :", os.path.basename(run_path))
  
		fit_results = open(MAT_fit_cache_path, 'r').read()

		if fit_results == 'MAT fit failed':
			if not cache_failed:
				# fit regardless of cached result
				try: 
					fit_results, settings = save_fit_results(run_path, plot=plot)
				except Exception as e:
					print(traceback.format_exc())
					print("Fitting ERROR at ", os.path.basename(run_path), '\n')
	
					with open(MAT_fit_cache_path, 'w') as f:
						f.write(str('MAT fit failed'))	
			else:
				print("Failed fit at :", os.path.basename(run_path))
				fit_results = {}

		else:
			fit_results = eval(open(MAT_fit_cache_path, 'r').read())
   
			settingsname = os.path.join(run_path, 'Settings.txt')
			settings = eval(open(settingsname, 'r').read())
   
	return fit_results, settings, timestamp



def get_row(run_path, **kwargs):
			
   fit_results, settings, timestamp = extract_fit(run_path, **kwargs)
   row = {**fit_results, **settings, **{'timestamp':timestamp}}
   
   return row

   
def get_data_frame(data_dir, parallel=True, in_process_run=False, **kwargs):
   
	run_path_arr = []
	rows = []
	
	for relative_path in os.listdir(data_dir):
		run_path_arr.append(os.path.join(data_dir, relative_path))
  
	if in_process_run:
		run_path_arr.pop()

	run_path_arr = sorted(run_path_arr)
	
	if parallel:
		with Pool(4) as p:
			rows = list(tqdm(p.imap(partial(get_row, **kwargs), run_path_arr), total=len(run_path_arr)))
	
	else:
		for run_path in tqdm(run_path_arr):
		   rows.append(get_row(run_path, **kwargs))

	return pd.DataFrame.from_dict(rows)

def add_wavemeter_data(df, wmeter_csv_path, window_size=100, num_rows=50):


	"""Extract unique frequnecy values from wavemeter data
	Returns:
		unique_levels (list): unique frequency values in wavemeter data
	"""
 
	# TODO: modify dataframe in place with frequency data
 
	wdata = pd.read_csv(wmeter_csv_path, skiprows=2)
	wdata.dropna(inplace=True)
	freq_data = np.array(wdata.iloc[:, 0])
	try:
		freq_data = np.array([float(item) for item in freq_data if item.replace('.','').isdigit()])
	except Exception as e:
		print(e)
 
	max_freq = freq_data.max()
	min_freq = freq_data.min()

	return freq_data, max_freq, min_freq

def plot_results(ax, dfs, max_freq, min_freq=0.0, mfc='red', fmt='o', ms=5, save_folder=False, xscale=1.0, yscale=1.0, **kwargs):
	FREQVSVOLT = 221.0 
	FREQVSCURR = 1.13
	
	if not type(dfs) == list:
		freqs = ((max_freq-PUMP_FREQUENCY)-(dfs.dropna()['tempV']-dfs.dropna()['tempV'].min())*FREQVSVOLT- (dfs.dropna()['currV']-dfs.dropna()['currV'].min())*FREQVSCURR)*xscale
		dfs=[dfs]
  
	plt.gcf().set_dpi(300)
	
	for df in dfs:
		df = df.dropna()
		ax.errorbar(freqs, 
			   df['ratio']*yscale,
			   yerr=df['ratioErr'],
			   fmt=fmt, mfc=mfc, color='black', ms=ms, **kwargs)
		ax.set_ylabel(r'$\mathbf{\frac{V_{ss, cat}}{V_{ss}}} $ ', **labeldict)
		ax.set_xlabel(r'$\Delta $ (GHz)', **labeldict)
	
	if save_folder:
		plt.savefig(os.path.join(save_folder, 'ratio_vs_freq.png'))
	
	return freqs, ax
  
	#return plt.gca(), plt.gcf()
	#plt.show()

def plot_spline_fit(ax, x, y, s=1, yerr=None, color='black', scolor='black',figsize=(12,5), save_folder=None, title='',alpha=0.5,dpi=200, label='plot',**kwargs):
	from scipy.interpolate import splev, splrep
	xnew = np.linspace(min(x), max(x), 3*len(x) )

	y = [b for a,b in sorted(zip(x,y), key=lambda pair: pair[0])]
	if yerr is not None:
		yerr = [b for a,b in sorted(zip(x,yerr), key=lambda pair: pair[0])]
 
	x = sorted(x)

	spl = splrep(x, y, s=s)
	ynew = splev(xnew, spl)

	
	plt.gcf().set_dpi(dpi)
	plt.gcf().set_size_inches(figsize)
	
	if yerr is not None:
		ax.errorbar(x, y, yerr=yerr, fmt='o', **kwargs)
	else:
		ax.plot(x,y, 'o', **kwargs)
	ax.plot(xnew, ynew, '-', color=scolor, alpha=alpha, label=label, **kwargs)
 
	ax.set_ylabel(r'$\mathbf{\frac{V_{ss, cat}}{V_{ss}}} $ ', **labeldict)
	ax.set_xlabel(r'$\Delta $ (GHz)', **labeldict)
 
	ax.set_title(title, **titledict)
	if save_folder:
		plt.savefig(os.path.join(save_folder, 'spline_ratio_vs_freq.png'))
	
	return ax
 
def plot_polyfit(x_data, y_data, spline_degree):
	
	coefficients = np.polyfit(x_data, y_data, spline_degree)

	x_interp = np.linspace(min(x_data), max(x_data), 100)
	y_interp = np.polyval(coefficients, x_interp)

	plt.scatter(x_data, y_data, label='Original Data')
	plt.plot(x_interp, y_interp, label='Polynomial Interpolation (Degree={})'.format(spline_degree))

def collect_plots(source, destination, plot_name):
	print(f'Collecting plots from {os.path.basename(source)}')
	import shutil

	os.makedirs(destination, exist_ok=True)

	plot_files = []
	for root, dirs, files in os.walk(source):
		
		for file in files:
			if file == plot_name:
				plot_files.append(os.path.join(root, file))

	for i, plot_file in enumerate(plot_files, start=0):
		new_filename = f'{i}{plot_name}'
		destination_path = os.path.join(destination, new_filename)
		shutil.copy(plot_file, destination_path)

def create_GIF(images_folder, image_name):
	import imageio
	with imageio.get_writer(os.path.join(images_folder, f'{image_name}movie.gif'), mode='I', duration=0.5) as writer:
		for filename in os.listdir(images_folder):
			if image_name in filename:
				image = imageio.imread(os.path.join(images_folder, filename))
				writer.append_data(image)

def staircase_fit(data, peak_height=0.1, distance=100, data_offset=1, window_size=1, inc_final_peak=True):
	def moving_average(arr, window_size):
		weights = np.ones(window_size) / window_size
		return np.convolve(arr, weights, mode='valid')

	convdata1 = moving_average(data, window_size)
	convdata2 = moving_average(data[data_offset+1:], window_size )
	final = convdata1[:len(convdata2)]-convdata2
	# plt.plot(data)
	# plt.plot(convdata1)
	# plt.plot(convdata2)
	# plt.show()
	# plt.plot(final)

	
	from scipy.signal import find_peaks
	x= final
	peaks, _ = find_peaks(x, height=peak_height, distance=distance)
	peaks = np.insert(peaks, 0, 0)
	levels = []
	plot_arr = []
	for i, peak in enumerate(peaks):
		
		if i < len(peaks) - 1:
			temp = data[ peaks[i]:peaks[i+1] ]
			plot_arr.extend( np.ones_like(temp)*np.mean(temp))
			levels.append(np.mean(temp))
	if inc_final_peak:
		temp = data[peaks[-1]:]
		levels.append(np.mean(temp))
		plot_arr.extend( np.ones_like(temp)*np.mean(temp))
  
	plt.plot(x)
	plt.plot(peaks, x[peaks], "x")
	plt.plot(np.zeros_like(x), "--", color="gray")
	plt.show()
	
	plt.plot(data)
	plt.plot(np.ravel((plot_arr)))
	plt.show()
	plt.close()
	plt.plot(np.array(levels)[np.where(abs(np.diff(levels))>0.05)[0]], 'o', ms=5)
 
	return levels

def load_single_run(run_path):
	filename = os.path.join(run_path, 'data.csv')
	bkfilename = os.path.join(run_path, 'data_oldPD.csv')
	settingsname = os.path.join(run_path, 'Settings.txt')
	
	dh1 = MTdataHost(SAMPLE_RATE)
	dh1.loadCATdata(fileName=filename, settingsName=settingsname)
	
	return dh1
	# *-----------------------
	# *RELATIVE SCATTERING RATE
	# *-----------------------

def get_rel_scattering_row(run_path_couple):
	run_path1, run_path2 = run_path_couple
	# run_path1 = os.path.join(data_folder, run_folder1)
	# run_path2 = os.path.join(data_folder, run_folder2)
	result = {}
	with open(os.path.join(run_path1, 'twoSettings.txt'), 'r') as f:
		settings = f.read() 
		import re

		pattern = r'(\w+)\s*=\s*\(([\d.]+),\s*([\d.]+)\)'

		matches = re.findall(pattern, settings)

		
		for match in matches:
			key = match[0]
			value1 = float(match[1])
			value2 = float(match[2])
			result[key] = (value1, value2)

		#print(result)
	with open(os.path.join(run_path2, 'twoSettings.txt'), 'r') as f:
		pass
	
	timestamp = get_timestamp(run_path1)
	fit_results1, fit_results2, fit_results, depth_ratio = get_rel_scattering(run_path1, run_path2)
	
	extracted_values = {
			'pa1': result['pd1'][0],
			'pd1': result['pd1'][1],
			'pa2': result['pd2'][0],
			'pd2': result['pd2'][1],
			'depth_ratio': 1/float(depth_ratio), # ratio between current and std settings
			'timestamp': timestamp,
			**fit_results
		}
	return extracted_values
 
def get_rel_scattering_df(data_folder, parallel=False, **kwargs):
	
	listdir = sorted(os.listdir(data_folder))
	run_path_couple_arr = [[os.path.join(data_folder,run_folder1),os.path.join(data_folder,run_folder2)] in [listdir[i:i+2] for i in range(len(listdir))[::2]]]
	 
 
	if parallel:
		with Pool(4) as p:
			rows = list(tqdm(p.imap(partial(get_rel_scattering_row, **kwargs), run_path_couple_arr), total=len(run_path_couple_arr)))
	
	try:
		for run_folder1, run_folder2 in tqdm([listdir[i:i+2] for i in range(len(listdir))[::2]]):
			try:
				run_path1 = os.path.join(data_folder, run_folder1)
				run_path2 = os.path.join(data_folder, run_folder2)
				result = {}
				with open(os.path.join(run_path1, 'twoSettings.txt'), 'r') as f:
					settings = f.read() 
					import re

					pattern = r'(\w+)\s*=\s*\(([\d.]+),\s*([\d.]+)\)'

					matches = re.findall(pattern, settings)

					
					for match in matches:
						key = match[0]
						value1 = float(match[1])
						value2 = float(match[2])
						result[key] = (value1, value2)

					#print(result)
				with open(os.path.join(run_path2, 'twoSettings.txt'), 'r') as f:
					pass
					#print(f.readlines())
				
				timestamp = get_timestamp(run_path1)
				fit_results1, fit_results2, fit_results, depth_ratio = get_rel_scattering(run_path1, run_path2)
				
				extracted_values = {
						'pa1': result['pd1'][0],
						'pd1': result['pd1'][1],
						'pa2': result['pd2'][0],
						'pd2': result['pd2'][1],
						'depth_ratio': 1/float(depth_ratio), # ratio between current and std settings
	  					'timestamp': timestamp,
						**fit_results
					}
				depth_ratios_df.append(extracted_values)
				
				print('\n')
			except Exception as e:
					print(traceback.format_exc())
					print(f'Error {e} at {run_folder1, run_folder2}')
	except Exception as e:
		print(f'Error {e}')

	depth_ratios_df = pd.DataFrame(depth_ratios_df)
 
	return depth_ratios_df

def get_rel_scattering(run_path1, run_path2):
	resultDict = {}
	
	resultDict1, scat_ratio1 = _load_single_run_rel_scat(run_path1, plot=True)
	resultDict['scat_ratio1'] = scat_ratio1
	resultDict2, scat_ratio2 = _load_single_run_rel_scat(run_path2, plot=True)
	resultDict['scat_ratio2'] = 1/scat_ratio2
	#print(f"scat_ratio 1, (2 inverted) = {scat_ratio1:.3f}, {1/scat_ratio2:.3f}")
	#scat_ratio_avg = (scat_ratio1+1/scat_ratio2)/2
	scat_ratio_avg = scat_ratio1
	resultDict['scat_ratio_avg'] = scat_ratio_avg
 
	Rratio = resultDict1['initMOTR']/resultDict2['initMOTR']
	resultDict['Rratio'] = Rratio
	#print(fr"Rratio = {resultDict1['initMOTR']:.3f} / {resultDict2['initMOTR']:.3f} = {Rratio:.3f}")
	depthRatio = np.sqrt(Rratio/scat_ratio_avg)
	
	return resultDict1, resultDict2, resultDict, depthRatio


def _load_single_run_rel_scat(run_path, plot=False, cache_all=False):
	filename = os.path.join(run_path, 'data.csv')
	settingsname = os.path.join(run_path, 'Settings.txt')
	
	MAT_fit_cache_path = os.path.join(run_path, 'resultDict.txt')
	fit_results = {}
	if not os.path.exists(MAT_fit_cache_path) or not cache_all:
		
		try: 
			dh1 = MTdataHost(SAMPLE_RATE)
			dh1.loadCATdata(fileName=filename, settingsName=settingsname)

			#dh1.tBaseline = 1
			dh1.tCATbackground = 1
			dh1.tLoad = 2
			dh1.timeLoad = 30
			dh1.tReload = dh1.tLoad + dh1.timeLoad
			dh1.timeReload = 1

			dh1.setOffset()
			#dh1.tCATbackground = dh1.tReload + dh1.timeReload 
			dh1.tBaseline = dh1.tReload + dh1.timeReload
			#dh1.setCATtiming()
			dh1.setAllCAT(0.002)

			print('FITTINGGGGGGGGGGGG')
			fit_results = dh1.getResults(run_path, store=True)
			if plot:
				dh1.storeFits(run_path, combined=True, separate=True)
		except Exception as e:
			print(traceback.format_exc())
			print("Fitting ERROR at ", os.path.basename(run_path), '\n')

			with open(MAT_fit_cache_path, 'w') as f:
				f.write(str('MAT fit failed'))
		
	else:
		print("Accessing cached results from :", os.path.basename(run_path))

		fit_results = open(MAT_fit_cache_path, 'r').read()

		if fit_results == 'MAT fit failed':
			print("Failed fit at :", os.path.basename(run_path))
			fit_results = {}

		else:
			fit_results = eval(open(MAT_fit_cache_path, 'r').read())


	
	#scat_ratio = fit_results['motSS']/(fit_results['reloadVolt']+fit_results['baseVolt'] - (fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))
	scat_ratio = (fit_results['motSS']+fit_results['baseVolt']-(fit_results['CATbackgroundVolt']+fit_results['noLightBackground']))/(fit_results['reloadVolt'])
	fit_results['scat_ratio'] = scat_ratio
 	#scat_ratio = dh1.motSS/(dh1.reloadVolt+dh1.baseVolt - (dh1.CATbackgroundVolt+dh1.noLightBackground))
	
	return fit_results, scat_ratio

def scat_rate(I, delta, gamma=6.065, Is=1.669):
	"""_summary_

	Args:
		I (float): intensity (Mhz)
		delta (float): detuning (Mhz)
		gamma (float, optional): linewidth (Mhz) Defaults to 6.065.
		Is (float, optional): Should be one of 3.576(isotropic), 2.503(pi), 1.669 (sigma+-). Defaults to 1.669.

	Returns:
		_type_: gamma: the scattering rate
	"""
	return gamma*I/(2*Is*(1+I/Is+4*(delta/gamma)**2))

if __name__ == '__main__':
	run_path = r"C:\Users\svars\OneDrive\Desktop\UBC Lab\CATExperiment\CATMeasurements\testPArun9\16-53-10"
	filename = os.path.join(run_path, 'data.csv')
	bkfilename = os.path.join(run_path, 'data_oldPD.csv')
	settingsname = os.path.join(run_path, 'Settings.txt')
	
	dh1 = MTdataHost(SAMPLE_RATE)
	dh1.loadCATdata(fileName=filename, settingsName=settingsname)
	
 	#dh1.CATbackgroundData(bkfilename)
	dh1.setAllCAT(0.002)
File loaded: RFmin = 49 MHz, t_mt = 1.050 s.
In [ ]:
scat_df['pd2'].unique()
Out[ ]:
array([82.4, 80.8, 86.4, 85.6, 80. , 84. , 81.6, 83.2, 88. , 87.2, 84.8])
In [ ]:
scat_df[scat_df['pd2'] == 87.2].sort_values('pa2')
Out[ ]:
pa1 pd1 pa2 pd2 depth_ratio timestamp scat_ratio1 scat_ratio2 scat_ratio_avg Rratio
42 1.85 84.0 0.400 87.2 0.347353 1900-01-01 19:09:45 1.174920 1.171009 1.172965 9.721695
86 1.85 84.0 0.545 87.2 0.442833 1900-01-01 20:24:04 1.019451 1.044619 1.032035 5.262776
20 1.85 84.0 0.690 87.2 0.427939 1900-01-01 18:30:58 0.963702 0.977641 0.970672 5.300407
64 1.85 84.0 0.835 87.2 0.438320 1900-01-01 19:48:55 0.915368 0.916960 0.916164 4.768597
53 1.85 84.0 0.980 87.2 0.460413 1900-01-01 19:29:10 0.895090 0.895015 0.895053 4.222342
9 1.85 84.0 1.125 87.2 0.503780 1900-01-01 18:11:29 0.880922 0.884991 0.882956 3.479020
97 1.85 84.0 1.270 87.2 0.508204 1900-01-01 20:42:28 0.881955 0.878685 0.880320 3.408510
75 1.85 84.0 1.415 87.2 0.447452 1900-01-01 20:07:55 0.525650 0.897981 0.711815 3.555288
108 1.85 84.0 1.560 87.2 0.438677 1900-01-01 21:00:42 0.671617 0.791841 0.731729 3.802428
31 1.85 84.0 1.705 87.2 0.457147 1900-01-01 18:50:01 0.894374 0.770456 0.832415 3.983172
119 1.85 84.0 1.850 87.2 0.539399 1900-01-01 21:17:36 0.916980 0.863904 0.890442 3.060445
In [ ]:
Is = np.linspace(0, 16, 50)
plt.plot(Is, scat_rate(Is, -6, Is=3.576), label=fr'$\delta = {-6}$ MHz')
plt.plot(Is, scat_rate(Is, -12, Is=3.576), label=fr'$\delta = {-12}$ MHz')
plt.legend()
Out[ ]:
<matplotlib.legend.Legend at 0x1b127577490>
In [ ]:
Is = np.linspace(0, 20, 50)
plt.plot(Is, scat_rate(Is, -6, Is=3.576), label=fr'$\delta = {-6}$ MHz')
plt.plot(Is, scat_rate(Is, -12, Is=3.576), label=fr'$\delta = {-12}$ MHz')
plt.legend()
Out[ ]:
<matplotlib.legend.Legend at 0x1b128d39450>
In [ ]:
Is = np.linspace(0, 20, 50)
plt.plot(Is, scat_rate(Is, -6), label=fr'$\delta = {-6}$ MHz')
plt.plot(Is, scat_rate(Is, -12), label=fr'$\delta = {-12}$ MHz')
plt.legend()
Out[ ]:
<matplotlib.legend.Legend at 0x1b125766bd0>
In [ ]:
scat_df[scat_df['pd2'] == 86.4].sort_values('pa2')
Out[ ]:
pa1 pd1 pa2 pd2 depth_ratio timestamp scat_ratio1 scat_ratio2 scat_ratio_avg Rratio
35 1.85 84.0 0.400 86.4 0.511844 1900-01-01 18:57:09 1.367766 1.359027 1.363396 5.204108
79 1.85 84.0 0.545 86.4 0.525969 1900-01-01 20:13:44 1.182420 1.171467 1.176944 4.254363
13 1.85 84.0 0.690 86.4 0.559041 1900-01-01 18:18:33 1.061138 1.081053 1.071096 3.427210
57 1.85 84.0 0.835 86.4 0.586697 1900-01-01 19:36:19 0.985139 0.991166 0.988153 2.870754
46 1.85 84.0 0.980 86.4 0.614100 1900-01-01 19:16:53 0.943083 0.918116 0.930599 2.467659
2 1.85 84.0 1.125 86.4 0.607973 1900-01-01 17:59:38 0.913230 0.914242 0.913736 2.472021
90 1.85 84.0 1.270 86.4 0.624881 1900-01-01 20:30:22 0.882347 0.856888 0.869617 2.227069
68 1.85 84.0 1.415 86.4 0.554044 1900-01-01 19:56:07 0.373924 0.881605 0.627764 2.045072
101 1.85 84.0 1.560 86.4 0.631545 1900-01-01 20:49:00 0.860806 0.840612 0.850709 2.132907
24 1.85 84.0 1.705 86.4 0.640179 1900-01-01 18:37:28 0.889485 0.854718 0.872102 2.127965
112 1.85 84.0 1.850 86.4 0.637039 1900-01-01 21:06:37 0.865055 0.877758 0.871406 2.147282
In [ ]:
scat_df[scat_df['pd2'] == 85.6].sort_values('pa2')
Out[ ]:
pa1 pd1 pa2 pd2 depth_ratio timestamp scat_ratio1 scat_ratio2 scat_ratio_avg Rratio
36 1.85 84.0 0.400 85.6 0.539871 1900-01-01 18:58:58 1.752941 1.686216 1.719579 5.899866
80 1.85 84.0 0.545 85.6 0.624180 1900-01-01 20:15:12 1.398177 1.370896 1.384537 3.553737
14 1.85 84.0 0.690 85.6 0.685161 1900-01-01 18:20:18 1.251750 1.253575 1.252663 2.668386
58 1.85 84.0 0.835 85.6 0.692262 1900-01-01 19:38:05 1.128834 1.088018 1.108426 2.312950
47 1.85 84.0 0.980 85.6 0.734132 1900-01-01 19:18:39 1.042219 1.026641 1.034430 1.919346
3 1.85 84.0 1.125 85.6 0.728236 1900-01-01 18:01:06 0.981404 0.958251 0.969827 1.828735
91 1.85 84.0 1.270 85.6 0.834622 1900-01-01 20:32:12 0.939187 0.925800 0.932494 1.338648
69 1.85 84.0 1.415 85.6 0.805686 1900-01-01 19:57:56 0.911669 0.904064 0.907867 1.398590
102 1.85 84.0 1.560 85.6 0.656743 1900-01-01 20:50:43 0.902292 0.359060 0.630676 1.462230
25 1.85 84.0 1.705 85.6 0.778898 1900-01-01 18:39:14 0.932598 0.854709 0.893653 1.473016
113 1.85 84.0 1.850 85.6 0.809052 1900-01-01 21:08:04 0.913318 0.862315 0.887817 1.356345
In [ ]:
scat_df[scat_df['pd2'] == 84.8].sort_values('pa2')
Out[ ]:
pa1 pd1 pa2 pd2 depth_ratio timestamp scat_ratio1 scat_ratio2 scat_ratio_avg Rratio
43 1.85 84.0 0.400 84.8 0.658808 1900-01-01 19:11:33 2.101544 1.934226 2.017885 4.649210
87 1.85 84.0 0.545 84.8 0.774275 1900-01-01 20:25:34 1.691370 1.630339 1.660855 2.770394
21 1.85 84.0 0.690 84.8 0.745315 1900-01-01 18:32:43 1.435244 1.435098 1.435171 2.583589
65 1.85 84.0 0.835 84.8 0.845951 1900-01-01 19:50:43 1.283336 1.256286 1.269811 1.774390
54 1.85 84.0 0.980 84.8 0.840807 1900-01-01 19:30:56 1.218582 1.155378 1.186980 1.679000
10 1.85 84.0 1.125 84.8 0.868733 1900-01-01 18:13:17 1.110531 1.112590 1.111561 1.472857
98 1.85 84.0 1.270 84.8 0.890098 1900-01-01 20:44:02 1.045075 1.050292 1.047684 1.322376
76 1.85 84.0 1.415 84.8 0.908164 1900-01-01 20:09:22 1.004774 0.987227 0.996000 1.207623
109 1.85 84.0 1.560 84.8 0.944827 1900-01-01 21:02:12 0.980162 0.974027 0.977094 1.094540
32 1.85 84.0 1.705 84.8 0.899708 1900-01-01 18:51:46 0.941765 0.928847 0.935306 1.155449
120 1.85 84.0 1.850 84.8 0.854043 1900-01-01 21:19:03 0.934381 0.929620 0.932000 1.277782
In [ ]:
scat_df[scat_df['pd2'] == 84.0].sort_values('pa2')
Out[ ]:
pa1 pd1 pa2 pd2 depth_ratio timestamp scat_ratio1 scat_ratio2 scat_ratio_avg Rratio
38 1.85 84.0 0.400 84.0 0.702123 1900-01-01 19:02:37 2.477427 2.327093 2.402260 4.872973
82 1.85 84.0 0.545 84.0 0.771320 1900-01-01 20:18:07 1.996017 1.892431 1.944224 3.267966
16 1.85 84.0 0.690 84.0 0.816019 1900-01-01 18:23:50 1.748755 1.755527 1.752141 2.631288
60 1.85 84.0 0.835 84.0 0.844290 1900-01-01 19:41:43 1.543287 1.515176 1.529232 2.145310
49 1.85 84.0 0.980 84.0 0.905646 1900-01-01 19:22:11 1.364308 1.310180 1.337244 1.630399
5 1.85 84.0 1.125 84.0 0.939389 1900-01-01 18:04:24 1.294236 1.238496 1.266366 1.435053
93 1.85 84.0 1.270 84.0 0.957234 1900-01-01 20:35:41 1.221736 1.171878 1.196807 1.306135
71 1.85 84.0 1.415 84.0 1.006276 1900-01-01 20:01:27 1.131507 1.076286 1.103897 1.090169
104 1.85 84.0 1.560 84.0 0.969718 1900-01-01 20:54:03 1.081414 1.022307 1.051861 1.118580
27 1.85 84.0 1.705 84.0 0.995999 1900-01-01 18:42:50 1.034659 1.020822 1.027741 1.036015
115 1.85 84.0 1.850 84.0 0.967908 1900-01-01 21:11:36 1.019432 1.003478 1.011455 1.079639
In [ ]:
scat_df[scat_df['pd2'] == 83.2].sort_values('pa2')
Out[ ]:
pa1 pd1 pa2 pd2 depth_ratio timestamp scat_ratio1 scat_ratio2 scat_ratio_avg Rratio
40 1.85 84.0 0.400 83.2 0.785396 1900-01-01 19:06:09 2.935946 2.696489 2.816218 4.565502
84 1.85 84.0 0.545 83.2 0.768479 1900-01-01 20:21:02 2.238408 2.160022 2.199215 3.723949
18 1.85 84.0 0.690 83.2 0.895618 1900-01-01 18:27:30 1.941086 1.954661 1.947873 2.428369
62 1.85 84.0 0.835 83.2 0.885332 1900-01-01 19:45:18 1.747427 1.730530 1.738979 2.218617
51 1.85 84.0 0.980 83.2 0.933890 1900-01-01 19:25:42 1.571625 1.489480 1.530553 1.754918
7 1.85 84.0 1.125 83.2 1.066557 1900-01-01 18:07:59 1.400588 1.371377 1.385982 1.218399
95 1.85 84.0 1.270 83.2 1.079691 1900-01-01 20:39:08 1.291910 1.254071 1.272991 1.092009
73 1.85 84.0 1.415 83.2 1.086728 1900-01-01 20:05:01 1.225772 1.195323 1.210547 1.025038
106 1.85 84.0 1.560 83.2 1.081401 1900-01-01 20:57:31 1.191620 1.148623 1.170121 1.000593
29 1.85 84.0 1.705 83.2 1.081760 1900-01-01 18:46:25 1.115233 1.099144 1.107188 0.946149
117 1.85 84.0 1.850 83.2 1.039424 1900-01-01 21:14:41 1.094836 1.065198 1.080017 0.999644
In [ ]:
Is = np.linspace(0, 20, 50)
plt.plot(Is, scat_rate(Is, -13.6), label=fr'$\delta = {-13.6}$ MHz')
plt.plot(Is, scat_rate(Is, -12), label=fr'$\delta = {-12}$ MHz')
plt.legend()
Out[ ]:
<matplotlib.legend.Legend at 0x1b12588c250>
In [ ]:
scat_df[scat_df['pd2'] == 82.4].sort_values('pa2')
Out[ ]:
pa1 pd1 pa2 pd2 depth_ratio timestamp scat_ratio1 scat_ratio2 scat_ratio_avg Rratio
33 1.85 84.0 0.400 82.4 0.675392 1900-01-01 18:53:31 3.367520 3.034449 3.200984 7.017337
77 1.85 84.0 0.545 82.4 0.693091 1900-01-01 20:10:49 2.585176 2.419364 2.502270 5.208986
11 1.85 84.0 0.690 82.4 0.992036 1900-01-01 18:15:02 2.319206 2.136323 2.227764 2.263677
55 1.85 84.0 0.835 82.4 0.943165 1900-01-01 19:32:43 1.983927 1.833870 1.908898 2.145892
44 1.85 84.0 0.980 82.4 0.977818 1900-01-01 19:13:21 1.810422 1.786704 1.798563 1.881091
0 1.85 84.0 1.125 82.4 1.060105 1900-01-01 17:56:41 1.651707 1.621480 1.636594 1.456274
88 1.85 84.0 1.270 82.4 1.063839 1900-01-01 20:27:05 1.539812 1.470934 1.505373 1.330123
66 1.85 84.0 1.415 82.4 1.141788 1900-01-01 19:52:32 1.391204 1.401317 1.396261 1.071015
99 1.85 84.0 1.560 82.4 1.087417 1900-01-01 20:45:40 1.332712 1.295215 1.313963 1.111198
22 1.85 84.0 1.705 82.4 1.109187 1900-01-01 18:34:17 1.283968 1.233511 1.258739 1.023120
110 1.85 84.0 1.850 82.4 1.014503 1900-01-01 21:03:41 1.229280 1.162525 1.195902 1.161955
In [ ]:
Is = np.linspace(0, 20, 50)
plt.plot(Is, scat_rate(Is, -15.2), label=fr'$\delta = {-15.2}$ MHz')
plt.plot(Is, scat_rate(Is, -12), label=fr'$\delta = {-12}$ MHz')
plt.legend()
Out[ ]:
<matplotlib.legend.Legend at 0x1b1285abf90>
In [ ]:
scat_df[scat_df['pd2'] == 81.6].sort_values('pa2')
Out[ ]:
pa1 pd1 pa2 pd2 depth_ratio timestamp scat_ratio1 scat_ratio2 scat_ratio_avg Rratio
39 1.85 84.0 0.400 81.6 0.636457 1900-01-01 19:04:25 4.012403 3.708037 3.860220 9.529576
83 1.85 84.0 0.545 81.6 0.815092 1900-01-01 20:19:35 2.968036 2.746715 2.857376 4.300845
17 1.85 84.0 0.690 81.6 0.467613 1900-01-01 18:25:41 2.601037 2.552349 2.576693 11.783930
61 1.85 84.0 0.835 81.6 1.052341 1900-01-01 19:43:34 2.295847 2.162626 2.229236 2.012995
50 1.85 84.0 0.980 81.6 1.049111 1900-01-01 19:23:58 2.136278 1.904376 2.020327 1.835601
6 1.85 84.0 1.125 81.6 0.777422 1900-01-01 18:06:11 1.871894 1.779275 1.825585 3.020563
94 1.85 84.0 1.270 81.6 1.248490 1900-01-01 20:37:26 1.706670 1.608603 1.657636 1.063454
72 1.85 84.0 1.415 81.6 0.878307 1900-01-01 20:03:16 1.576514 1.502483 1.539499 1.995660
105 1.85 84.0 1.560 81.6 0.949846 1900-01-01 20:55:47 1.476523 1.427885 1.452204 1.609611
28 1.85 84.0 1.705 81.6 1.217380 1900-01-01 18:44:38 1.418993 1.343861 1.381427 0.932129
116 1.85 84.0 1.850 81.6 0.661591 1900-01-01 21:13:13 1.344940 -0.131274 0.606833 1.386405
In [ ]:
Is = np.linspace(0, 20, 50)
plt.plot(Is, scat_rate(Is, -16.8), label=fr'$\delta = {-16.8}$ MHz')
plt.plot(Is, scat_rate(Is, -12), label=fr'$\delta = {-12}$ MHz')
plt.legend()
Out[ ]:
<matplotlib.legend.Legend at 0x1b126f47490>
In [ ]:
Is = np.linspace(0, 20, 50)
plt.plot(Is, scat_rate(Is, -18.4), label=fr'$\delta = {-18.4}$ MHz')
plt.plot(Is, scat_rate(Is, -12), label=fr'$\delta = {-12}$ MHz')
plt.legend()
Out[ ]:
<matplotlib.legend.Legend at 0x1b126e59bd0>
In [ ]:
scat_df[scat_df['pd2'] == 80.8].sort_values('pa2')
Out[ ]:
pa1 pd1 pa2 pd2 depth_ratio timestamp scat_ratio1 scat_ratio2 scat_ratio_avg Rratio
34 1.85 84.0 0.400 80.8 0.690276 1900-01-01 18:55:20 4.662485 4.455622 4.559054 9.568189
78 1.85 84.0 0.545 80.8 0.921376 1900-01-01 20:12:17 3.428010 3.151522 3.289766 3.875176
12 1.85 84.0 0.690 80.8 NaN 1900-01-01 18:16:49 2.957568 2.682171 2.819870 -18.151483
56 1.85 84.0 0.835 80.8 0.836623 1900-01-01 19:34:31 2.566181 2.419181 2.492681 3.561288
45 1.85 84.0 0.980 80.8 1.094885 1900-01-01 19:15:07 2.287358 2.320767 2.304062 1.922016
1 1.85 84.0 1.125 80.8 0.834277 1900-01-01 17:58:10 2.085987 2.014917 2.050452 2.945972
89 1.85 84.0 1.270 80.8 0.686975 1900-01-01 20:28:39 1.898959 1.822330 1.860645 3.942587
67 1.85 84.0 1.415 80.8 0.979225 1900-01-01 19:54:20 1.767689 1.668228 1.717958 1.791626
100 1.85 84.0 1.560 80.8 0.758703 1900-01-01 20:47:19 1.675351 1.603392 1.639372 2.847956
23 1.85 84.0 1.705 80.8 0.794021 1900-01-01 18:35:45 1.573369 1.256980 1.415174 2.244638
111 1.85 84.0 1.850 80.8 0.701278 1900-01-01 21:05:09 1.532028 0.903196 1.217612 2.475871
In [ ]:
scat_df[scat_df['pd2'] == 80.0].sort_values('pa2')
Out[ ]:
pa1 pd1 pa2 pd2 depth_ratio timestamp scat_ratio1 scat_ratio2 scat_ratio_avg Rratio
37 1.85 84.0 0.400 80.0 0.331972 1900-01-01 19:00:50 5.306803 3.835458 4.571131 41.478163
81 1.85 84.0 0.545 80.0 0.717299 1900-01-01 20:16:39 4.047118 3.348059 3.697588 7.186516
15 1.85 84.0 0.690 80.0 0.800722 1900-01-01 18:22:04 3.387196 3.061712 3.224454 5.029131
59 1.85 84.0 0.835 80.0 0.777615 1900-01-01 19:39:54 2.952769 2.673321 2.813045 4.652088
48 1.85 84.0 0.980 80.0 0.777911 1900-01-01 19:20:25 2.570514 2.109400 2.339957 3.866766
4 1.85 84.0 1.125 80.0 0.566797 1900-01-01 18:02:39 2.408469 2.327947 2.368208 7.371643
92 1.85 84.0 1.270 80.0 0.734950 1900-01-01 20:33:57 2.196384 2.158795 2.177589 4.031438
70 1.85 84.0 1.415 80.0 0.776538 1900-01-01 19:59:43 2.037439 1.911285 1.974362 3.274170
103 1.85 84.0 1.560 80.0 0.638328 1900-01-01 20:52:23 1.905388 1.832009 1.868699 4.586181
26 1.85 84.0 1.705 80.0 0.711072 1900-01-01 18:41:02 1.808846 1.669553 1.739200 3.439718
114 1.85 84.0 1.850 80.0 0.370453 1900-01-01 21:09:50 1.760017 0.904101 1.332059 9.706361
In [ ]:
Is = np.linspace(0, 20, 50)
plt.plot(Is, scat_rate(Is, -20.0), label=fr'$\delta = {-20.0}$ MHz')
plt.plot(Is, scat_rate(Is, -12), label=fr'$\delta = {-12}$ MHz')
plt.legend()
Out[ ]:
<matplotlib.legend.Legend at 0x1b12608c250>
In [ ]:
Is = np.linspace(0, 20, 50)
plt.plot(Is, scat_rate(Is, -20.0, 3.576), label=fr'$\delta = {-20.0}$ MHz')
plt.plot(Is, scat_rate(Is, -12, 3.576), label=fr'$\delta = {-12}$ MHz')
plt.legend()
Out[ ]:
<matplotlib.legend.Legend at 0x1b126b9c250>
In [ ]:
import matplotlib.pyplot as plt
import numpy as np
from scipy.interpolate import griddata

import lmfit
from lmfit.lineshapes import gaussian2d, lorentzian
In [ ]:
npoints = 10000
np.random.seed(2021)
x = np.random.rand(npoints)*10 - 4
y = np.random.rand(npoints)*5 - 3
z = gaussian2d(x, y, amplitude=30, centerx=2, centery=-.5, sigmax=.6, sigmay=.8)
z += 2*(np.random.rand(*z.shape)-.5)
error = np.sqrt(z+1)